Skip to content

Commit

Permalink
add unit tests to verify default presets in block and classic themes
Browse files Browse the repository at this point in the history
  • Loading branch information
madhusudhand committed Mar 28, 2024
1 parent bc79b36 commit e22b910
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
100 changes: 100 additions & 0 deletions phpunit/class-wp-theme-json-resolver-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ public function test_translations_are_applied() {
'padding' => true,
'blockGap' => true,
),
'shadow' => array(
'presets' => array(
'theme' => array(
array(
'name' => 'Natural',
'slug' => 'natural',
'shadow' => '2px 2px 3px #000',
),
array(
'name' => 'Test',
'slug' => 'test',
'shadow' => '2px 2px 3px #000',
),
),
),
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
Expand Down Expand Up @@ -540,6 +556,22 @@ public function test_merges_child_theme_json_into_parent_theme_json() {
),
),
),
'shadow' => array(
'presets' => array(
'theme' => array(
array(
'name' => 'Natural',
'slug' => 'natural',
'shadow' => '2px 2px 3px #000',
),
array(
'name' => 'Test',
'slug' => 'test',
'shadow' => '2px 2px 3px #000',
),
),
),
),
'spacing' => array(
'blockGap' => true,
'units' => array( 'rem' ),
Expand Down Expand Up @@ -1039,4 +1071,72 @@ public function test_get_style_variations_returns_all_variations() {
$actual_settings
);
}

public function test_theme_shadow_presets_do_not_override_default_shadow_presets() {
switch_theme( 'block-theme' );

$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();
$actual_settings = $theme_json->get_settings()['shadow']['presets'];

$expected_settings = array(
'default' => array(
array(
'name' => 'Natural',
'shadow' => '6px 6px 9px rgba(0, 0, 0, 0.2)',
'slug' => 'natural',
),
array(
'name' => 'Deep',
'shadow' => '12px 12px 50px rgba(0, 0, 0, 0.4)',
'slug' => 'deep',
),
array(
'name' => 'Sharp',
'shadow' => '6px 6px 0px rgba(0, 0, 0, 0.2)',
'slug' => 'sharp',
),
array(
'name' => 'Outlined',
'shadow' => '6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1)',
'slug' => 'outlined',
),
array(
'name' => 'Crisp',
'shadow' => '6px 6px 0px rgba(0, 0, 0, 1)',
'slug' => 'crisp',
),
),
'theme' => array(
array(
'name' => 'Test',
'shadow' => '2px 2px 3px #000',
'slug' => 'test',
),
),
);

wp_recursive_ksort( $actual_settings );
wp_recursive_ksort( $expected_settings );

$this->assertSame(
$expected_settings,
$actual_settings
);
}

public function test_shadow_default_presets_value_for_block_and_classic_themes() {
$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();

$default_presets_for_classic = $theme_json->get_settings()['shadow']['defaultPresets'];
$this->assertFalse( $default_presets_for_classic );

switch_theme( 'block-theme' );
$theme_json_resolver = new WP_Theme_JSON_Resolver_Gutenberg();
$theme_json = $theme_json_resolver->get_merged_data();

$default_presets_for_block = $theme_json->get_settings()['shadow']['defaultPresets'];
$this->assertTrue( $default_presets_for_block );
}
}
14 changes: 14 additions & 0 deletions phpunit/data/themedir1/block-theme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
"padding": true,
"blockGap": true
},
"shadow": {
"presets": [
{
"name": "Natural",
"slug": "natural",
"shadow": "2px 2px 3px #000"
},
{
"name": "Test",
"slug": "test",
"shadow": "2px 2px 3px #000"
}
]
},
"blocks": {
"core/paragraph": {
"color": {
Expand Down

0 comments on commit e22b910

Please sign in to comment.