Skip to content

Commit

Permalink
Tests: Remove the ::append_to_selector() method from `Tests_Theme_w…
Browse files Browse the repository at this point in the history
…pThemeJson`.

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 WordPress/gutenberg#32190.

Follow-up to [51051].

See #52991.

git-svn-id: https://develop.svn.wordpress.org/trunk@51054 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 1, 2021
1 parent d8c4ba3 commit f5ca52c
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ function test_get_stylesheet() {
);
}

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(
Expand Down Expand Up @@ -619,28 +646,6 @@ function test_get_editor_settings_no_theme_support() {
$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
*/
Expand Down

0 comments on commit f5ca52c

Please sign in to comment.