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

Duotone: Style Engine: Add unit test and associated refactoring #49033

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

scruffian
Copy link
Contributor

@scruffian scruffian commented Mar 13, 2023

What?

This adds a unit test to the style engine to test that duotone properties are correctly output.

Why?

This catches a bug that was fixed in #49004.

How?

Call the style engine with static strings

Testing Instructions

npm run test:unit:php -- --filter 'WP_Block_Supports_Duotone_Test'
npm run test:unit:php -- --filter 'WP_Style_Engine_Test'

Question

Since this is really testing a fix in wp_kses, is this still a useful test to have?

@scruffian scruffian added the [Package] Style Engine /packages/style-engine label Mar 13, 2023
@scruffian scruffian requested a review from spacedmonkey as a code owner March 13, 2023 13:59
@scruffian scruffian self-assigned this Mar 13, 2023
@@ -290,6 +290,59 @@ function gutenberg_tinycolor_string_to_rgb( $color_str ) {
}
}

class WP_Duotone {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if there are some WordPress PHP style guidelines somewhere, but I always see classes in their own file named class-wp-something.php. Should we do the same for this class?

I also often see the Gutenberg version with a _Gutenberg suffix. In some places I think this is automatically added during the build process, but I don't think anything is done for lib. Do we need to include the suffix here so the name is WP_Duotone_Gutenberg?

@@ -676,4 +676,35 @@ public function test_should_dedupe_and_merge_css_rules() {

$this->assertSame( '.gandalf{color:white;height:190px;border-style:dotted;padding:10px;margin-bottom:100px;}.dumbledore,.rincewind{color:grey;height:90px;border-style:dotted;}', $compiled_stylesheet );
}

/**
* Tests returning a generated stylesheet from a set of duotone rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more of an integration test than a unit test for the style engine since it's testing both get_id_selector_property_and_maybe_svg and gutenberg_style_engine_get_stylesheet_from_css_rules. Is there a better place to put integration tests than mixed in with the unit tests for the style engine package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the approach to just use strings.

@@ -290,6 +290,59 @@ function gutenberg_tinycolor_string_to_rgb( $color_str ) {
}
}

class WP_Duotone {
static function get_id_selector_property_and_maybe_svg( $duotone_attr, $duotone_support ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When there are words like and and maybe in a function name, it means the function is probably doing too much. And in this case, it feels like that even more so because it generates four outputs, one of which may be null.

@github-actions
Copy link

Flaky tests detected in b819d17.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4405744658
📝 Reported issues:

Copy link
Contributor

@ajlende ajlende left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@ajlende ajlende merged commit 7709c89 into trunk Mar 14, 2023
@ajlende ajlende deleted the add/duotone-test-to-style-engine branch March 14, 2023 16:18
@github-actions github-actions bot added this to the Gutenberg 15.4 milestone Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Style Engine /packages/style-engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants