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

Elements: Add unit tests to cover both classname application and style generation #5418

Conversation

aaronrobertshaw
Copy link

This is a backport PR that includes the following PHP Gutenberg changes:

WordPress/gutenberg#55113

It provides additional unit tests for the elements block support and its associated classname and style generation.

Trac ticket: https://core.trac.wordpress.org/ticket/59555


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @aaronrobertshaw! I've left some feedback above 🙂

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Thanks @aaronrobertshaw, this looks great so far. I left a bit of additional feedback.

Comment on lines 31 to 48
public function register_block_with_color_settings( $color_settings ) {
$this->test_block_name = 'test/element-block-supports';

register_block_type(
$this->test_block_name,
array(
'api_version' => 3,
'attributes' => array(
'style' => array(
'type' => 'object',
),
)
),
'supports' => array(
'color' => $color_settings,
),
)
);
$this->assertSame(
$result,
'<p class="wp-elements-1">Hello <a href="http://www.wordpress.org/">WordPress</a>!</p>'
);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this logic should run as part of set_up() instead of in the individual tests. So either this method should be removed, or alternatively it should be called in set_up(). Also, if we keep the method, it should become private.

The block is always registered like that, and tear_down() calls the equivalent unregister_block_type(), so there should be parity with that.

Copy link
Author

Choose a reason for hiding this comment

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

I'm likely missing something here but I'm not following the suggestion. The block type's supports config differs across the data sets used by the test.

While splitting these tests into separate files per function, I've moved the block type registration into the test itself so the per-test configuration might be more obvious.

tests/phpunit/tests/block-supports/elements.php Outdated Show resolved Hide resolved
tests/phpunit/tests/block-supports/elements.php Outdated Show resolved Hide resolved
@aaronrobertshaw
Copy link
Author

Appreciate all the feedback @costdev & @felixarntz 👍

I believe I've addressed everything now. Let me know if I missed anything

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @aaronrobertshaw, LGTM!

@felixarntz felixarntz requested a review from costdev October 9, 2023 16:21
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks @aaronrobertshaw! Looks good to go!

@felixarntz
Copy link
Member

Committed in https://core.trac.wordpress.org/changeset/56806 - which for some reason doesn't show up yet, but proof it was committed can be found here: 4d5859b 😆

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.

3 participants