bobbingwide / field-block-for-acf-pro

Field block for ACF PRO
https://www.oik-plugins.com/oik-plugins/field-block-for-acf-pro/
GNU General Public License v2.0
3 stars 0 forks source link

Develop in situ PHPUnit tests #15

Open bobbingwide opened 1 year ago

bobbingwide commented 1 year ago

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 commented 1 year ago

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

Longer term solution

bobbingwide commented 1 year ago

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 commented 11 months ago

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 commented 8 months ago

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 commented 8 months ago

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