Open bobbingwide opened 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.
tearDown()
to not call _restore_hooks()
_restore_hooks()
is run during tearDown()
.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
.
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.
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/
Content tests to be added: Image, File, WYSIWYG Editor, oEmbed, Gallery
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