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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions phpunit/style-engine/style-engine-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,30 @@ 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.

*
* This is testing this fix: https://github.com/WordPress/gutenberg/pull/49004
*
* @covers ::gutenberg_style_engine_get_stylesheet_from_css_rules
* @covers WP_Style_Engine_Gutenberg::compile_stylesheet_from_css_rules
*/
public function test_should_return_stylesheet_from_duotone_css_rules() {
$css_rules = array(
array(
'selector' => '.wp-duotone-ffffff-000000-1',
'declarations' => array(
// !important is needed because these styles
// render before global styles,
// and they should be overriding the duotone
// filters set by global styles.
'filter' => "url('#wp-duotone-ffffff-000000-1') !important",
),
),
);

$compiled_stylesheet = gutenberg_style_engine_get_stylesheet_from_css_rules( $css_rules, array( 'prettify' => false ) );
$this->assertSame( ".wp-duotone-ffffff-000000-1{filter:url('#wp-duotone-ffffff-000000-1') !important;}", $compiled_stylesheet );
}
}