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

Run the unit tests for the lowest and latest versions of wp/php #63

Merged
merged 13 commits into from
Jun 17, 2024

Conversation

ingeniumed
Copy link
Contributor

Description

This will update the PHP unit tests workflow to run for the lowest WP/PHP version we support and the latest combo as well. That way at all times we are ensuring our code is working as expected. It also updates some of the actions that are used, to take advantage of the caching/etc improvements.

@ingeniumed ingeniumed requested a review from a team as a code owner May 26, 2024 04:02
@alecgeatches alecgeatches self-assigned this Jun 10, 2024
@alecgeatches
Copy link
Contributor

alecgeatches commented Jun 10, 2024

@ingeniumed The tests have been fixed, would love a review! The main issue here is that some tests were using core blocks directly, and as their attributes changed between WordPress updates it caused direct attribute comparisons to fail. A lot of tests were immune to this problem by registering their own block definitions for tests, like attribute tests:

$this->register_block_with_attributes( 'test/paragraph', [
'content' => [
'type' => 'string',
'source' => 'html',
'selector' => 'p',
],
] );

However, REST API and GraphQL tests were using core blocks directly:

$html = '
<!-- wp:heading -->
<h2>Heading 1</h2>
<!-- /wp:heading -->
<!-- wp:quote -->
<blockquote class="wp-block-quote">
<!-- wp:paragraph -->
<p>Text in quote</p>
<!-- /wp:paragraph -->
<cite>~ Citation, 2023</cite>
</blockquote>
<!-- /wp:quote -->

...

$expected_blocks = [
[
'name' => 'core/heading',
'attributes' => [
'content' => 'Heading 1',
'level' => 2,
],
],

The problem is that when a block.json attribute is added or changed in a new WordPress version, any test using those blocks and attribute comparison would fail. This was a bit more difficult to fix than the first example test because REST API and GraphQL tests that fire off a request and don't have an easy way to specify a custom registry.

In the changes, I've added a couple of register_global_block_with_attributes() methods (in REST and GraphQL tests respectively) that modify the "real" registry, and then automatically unregister custom blocks after the test completes. This allows us to use mocked core blocks without having a direct dependency on the block's definition in WordPress.

This should fix all test breaks related to core block attribute changes, and make future WordPress testing for this plugin less brittle.

Copy link
Contributor Author

@ingeniumed ingeniumed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements to the tests! Just a minor item to tweak before this can be 🚢

* Version: 1.2.3
* Requires at least: 5.9.0
* Version: 1.2.4
* Requires at least: 6.0
* Tested up to: 6.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update this to 6.6 btw

@alecgeatches alecgeatches changed the base branch from trunk to planned-release/1.2.4 June 17, 2024 18:26
@alecgeatches alecgeatches merged commit 3ee11ca into planned-release/1.2.4 Jun 17, 2024
3 checks passed
@alecgeatches alecgeatches deleted the update/tests-workflow-forwp-php branch June 17, 2024 18:30
@alecgeatches alecgeatches mentioned this pull request Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants