-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Elements: Add unit tests to cover both classname application and style generation #5418
Conversation
There was a problem hiding this 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 🙂
There was a problem hiding this 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.
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>' | ||
); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Appreciate all the feedback @costdev & @felixarntz 👍 I believe I've addressed everything now. Let me know if I missed anything |
There was a problem hiding this 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!
There was a problem hiding this 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!
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 😆 |
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.