Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop in situ PHPUnit tests #15

Open
bobbingwide opened this issue Aug 17, 2023 · 5 comments
Open

Develop in situ PHPUnit tests #15

bobbingwide opened this issue Aug 17, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

Before making any major changes to the ACF Field block plugin it makes sense to develop a set of in situ PHPUnit tests that can be used to confirm that the server side rendering of the block is working for each supported field type.
These tests can be run for each new version of ACF PRO, WordPress and whenever making changes.

See How to run PHPUnit tests for WordPress pligins in situ

@bobbingwide bobbingwide added the enhancement New feature or request label Aug 17, 2023
@bobbingwide bobbingwide self-assigned this Aug 17, 2023
@bobbingwide
Copy link
Owner Author

bobbingwide commented Sep 2, 2023

I've had some difficulty creating a framework for the PHPUnit tests.
Rather than dynamically creating the field groups and fields I've had to resort to defining a set of field groups for a new CPT called test-acf-fields.
And then I had difficulty getting more than one test to run.

The call to get_field('acf-field-name'); fails in the second test case.

This is because, during the method tearDown(), in class WP_UnitTestCase, in oik-batch\tests\testcase.php, the WordPress test suite resets the hooks that ACF has added. This removes the filter function for acf/pre_load_post_id which is needed to determine the value of the acf-field-name from the block's attributes.

Workaround

  • Change tearDown() to not call _restore_hooks()

Longer term solution

  • Allow the test case to determine whether or not _restore_hooks() is run during tearDown().

@bobbingwide
Copy link
Owner Author

bobbingwide commented Sep 5, 2023

I have to resort to defining a set of field groups for a new CPT called test-acf-fields.

To do this I imported the acf-json from the original theme 'genesis-oik', to the active theme 'Fizzie',
and changed the Location Rules to this CPT.

This works for the s.b/wordpress environment, but not for others such as s.b/oikcom, where the block examples are documented.

It would make sense for these .json files to be stored in the tests\acf-json subdirectory so that they could be loaded into other environments. In which case they may as well support both CPTs test-acf-fields and block_examples.

@bobbingwide
Copy link
Owner Author

So far I've added tests for 5 field types. These have been tested with PHP 8.1 and PHP 8.2
Further tests need adding for the other field types
plus some pre-requisite tests such as confirming that Advanced Custom Fields PRO is activated.

@bobbingwide
Copy link
Owner Author

bobbingwide commented Feb 3, 2024

So far I've added tests for 5 field types.

Actually 6 - text, text-area, number, range, email, url

This one to do for the basic field types: password.

Then for the rest see the table of field types supported in https://www.oik-plugins.com/oik-plugins/field-block-for-acf-pro/

@bobbingwide
Copy link
Owner Author

Content tests to be added: Image, File, WYSIWYG Editor, oEmbed, Gallery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant