Skip to content
Closed
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
66 changes: 66 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function tear_down() {
unregister_block_type( 'test/feature-selector' );
}

if ( $registry->is_registered( 'test/deprecated-feature-selector' ) ) {
unregister_block_type( 'test/deprecated-feature-selector' );
}

parent::tear_down();
}

Expand Down Expand Up @@ -889,6 +893,68 @@ public function test_get_stylesheet_preset_css_vars_use_feature_selector() {
);
}

/**
* Tests that feature selectors defined as `__experimentalSelector` inside
* the `supports` property are correctly output in the stylesheet.
*
* @ticket 66640
*/
public function test_get_stylesheet_with_deprecated_feature_level_selectors() {
register_block_type(
'test/deprecated-feature-selector',
array(
'api_version' => 3,
'supports' => array(
'color' => array(
'__experimentalSelector' => 'h2, h3',
),
'typography' => array(
'fontSize' => true,
),
),
)
);

$theme_json = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'custom' => false,
'palette' => array(
array(
'slug' => 'green',
'color' => 'green',
),
),
),
'typography' => array(
'fontSize' => true,
),
),
'styles' => array(
'blocks' => array(
'test/deprecated-feature-selector' => array(
'color' => array(
'text' => 'green',
),
'typography' => array(
'fontSize' => '3em',
),
),
),
),
)
);

$base_styles = ':root{--wp--preset--color--green: green;}';
$block_styles = ':root :where(.wp-block-test-deprecated-feature-selector){font-size: 3em;}:root :where(.wp-block-test-deprecated-feature-selector h2, .wp-block-test-deprecated-feature-selector h3){color: green;}';
$preset_styles = '.has-green-color{color: var(--wp--preset--color--green) !important;}.has-green-background-color{background-color: var(--wp--preset--color--green) !important;}.has-green-border-color{border-color: var(--wp--preset--color--green) !important;}';
$expected = $base_styles . $block_styles . $preset_styles;

$this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles', 'presets', 'variables' ), null, array( 'skip_root_layout_styles' => true ) ) );
}

/**
* @ticket 53175
* @ticket 54336
Expand Down
Loading