From f5ca52c61794eb6a2082b1aec647de56344f2481 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 1 Jun 2021 11:30:05 +0000 Subject: [PATCH] Tests: Remove the `::append_to_selector()` method from `Tests_Theme_wpThemeJson`. The method exists in the `WP_Theme_JSON` class and appears to be erroneously duplicated in the test class. Add a unit test that was meant to be included instead, as per https://github.com/WordPress/gutenberg/pull/32190. Follow-up to [51051]. See #52991. git-svn-id: https://develop.svn.wordpress.org/trunk@51054 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/theme/wpThemeJson.php | 49 +++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index aceb3bd73b..f5bab760c0 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -170,6 +170,33 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase { ); } + function test_get_stylesheet_preset_classes_work_with_compounded_selectors() { + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'settings' => array( + 'blocks' => array( + 'core/heading' => array( + 'color' => array( + 'palette' => array( + array( + 'slug' => 'white', + 'color' => '#fff', + ), + ), + ), + ), + ), + ), + ) + ); + + $this->assertEquals( + 'h1.has-white-color,h2.has-white-color,h3.has-white-color,h4.has-white-color,h5.has-white-color,h6.has-white-color{color: #fff !important;}h1.has-white-background-color,h2.has-white-background-color,h3.has-white-background-color,h4.has-white-background-color,h5.has-white-background-color,h6.has-white-background-color{background-color: #fff !important;}', + $theme_json->get_stylesheet( 'block_styles' ) + ); + } + function test_get_stylesheet_preset_rules_come_after_block_rules() { $theme_json = new WP_Theme_JSON( array( @@ -619,28 +646,6 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } - /** - * Function that appends a sub-selector to a existing one. - * - * Given the compounded $selector "h1, h2, h3" - * and the $to_append selector ".some-class" the result will be - * "h1.some-class, h2.some-class, h3.some-class". - * - * @param string $selector Original selector. - * @param string $to_append Selector to append. - * - * @return string - */ - private static function append_to_selector( $selector, $to_append ) { - $new_selectors = array(); - $selectors = explode( ',', $selector ); - foreach ( $selectors as $sel ) { - $new_selectors[] = $sel . $to_append; - } - - return implode( ',', $new_selectors ); - } - /** * @ticket 52991 */