Support

Account

Home Forums General Issues Setting up mock data for automated tests

Solving

Setting up mock data for automated tests

  • I have a project that uses ACF to generate fields in the pages, and I output those fields in my REST API responses.

    I searched the net but it doesn’t seem to be a popular issue:

    How do you mock the data for the created fields? I know that they are stored in the post meta, and I could just create a mock page with WP test factory, and then use update_field(), but I’d need the correct way to see what data should go in there based on my fields.

    Is there an easy way to see this data and how it’s saved in the DB so that I can mock it in my test?

  • There isn’t any tool that I know of that will create dummy acf data. This one is good, but you need to create filters to insert content for ACF fields https://github.com/bordoni/fakerpress which means you’ve already gotta know how ACF stores data for each field.

    Each field stores data in a different way, not all fields are special but it would still take pages to explain in all. Most fields simply store text values of the input.

    I would say to create at least one post with the fields and then search the postmeta table for that post ID to see how it’s stored. Then if you don’t understand what you’re seeing for a specific field type to let me know and I’ll explain it.

  • Yeah, I know I can go through postmeta table and list all the fields, but I’m trying to avoid that.

    I even thought of hooking to post save and trying to see what will be saved there, but this seemed like too much work for setting up automated tests.

    Well, if there are no simple ways of doing that I’ll just avoid testing this part, until I can just refactor everything to core editor :S

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Setting up mock data for automated tests’ is closed to new replies.