Skip to content

Commit

Permalink
Changes from phpunit/class-wp-theme-json-test.php
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Dec 13, 2021
1 parent 897059c commit 16d6c97
Showing 1 changed file with 218 additions and 6 deletions.
224 changes: 218 additions & 6 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ public function test_get_settings_presets_are_keyed_by_origin() {
$this->assertEqualSetsWithIndex( $expected_no_origin, $actual_no_origin );
}

function test_get_settings_using_opt_in_key() {
function test_get_settings_appearance_true_opts_in() {
$theme_json = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'appearanceTools' => true,
'spacing' => array(
'blockGap' => false, // This should override appearanceTools.
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
Expand All @@ -217,6 +220,9 @@ function test_get_settings_using_opt_in_key() {
'typography' => array(
'lineHeight' => false, // This should override appearanceTools.
),
'spacing' => array(
'blockGap' => null,
),
),
),
),
Expand All @@ -235,7 +241,7 @@ function test_get_settings_using_opt_in_key() {
'link' => true,
),
'spacing' => array(
'blockGap' => true,
'blockGap' => false,
'margin' => true,
'padding' => true,
),
Expand All @@ -259,7 +265,7 @@ function test_get_settings_using_opt_in_key() {
'link' => true,
),
'spacing' => array(
'blockGap' => true,
'blockGap' => false,
'margin' => true,
'padding' => true,
),
Expand All @@ -273,6 +279,54 @@ function test_get_settings_using_opt_in_key() {
$this->assertEqualSetsWithIndex( $expected, $actual );
}

function test_get_settings_appearance_false_does_not_opt_in() {
$theme_json = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'appearanceTools' => false,
'border' => array(
'width' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'typography' => array(
'lineHeight' => false,
),
),
),
),
)
);

$actual = $theme_json->get_settings();
$expected = array(
'appearanceTools' => false,
'border' => array(
'width' => true,
),
'blocks' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => false,
),
),
'core/group' => array(
'typography' => array(
'lineHeight' => false,
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $actual );
}

/**
* @ticket 54336
*/
Expand Down Expand Up @@ -1133,13 +1187,14 @@ public function test_merge_incoming_data_null_presets() {
$this->assertEqualSetsWithIndex( $expected, $actual );
}

public function test_merge_incoming_data_removes_theme_presets_with_slugs_as_default_presets() {
public function test_merge_incoming_data_color_presets_with_same_slugs_as_default_are_removed() {
$defaults = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'palette' => array(
'defaultPalette' => true,
'palette' => array(
array(
'slug' => 'red',
'color' => 'red',
Expand Down Expand Up @@ -1218,7 +1273,7 @@ public function test_merge_incoming_data_removes_theme_presets_with_slugs_as_def
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'palette' => array(
'palette' => array(
'default' => array(
array(
'slug' => 'red',
Expand All @@ -1239,6 +1294,7 @@ public function test_merge_incoming_data_removes_theme_presets_with_slugs_as_def
),
),
),
'defaultPalette' => true,
),
'blocks' => array(
'core/paragraph' => array(
Expand Down Expand Up @@ -1271,6 +1327,162 @@ public function test_merge_incoming_data_removes_theme_presets_with_slugs_as_def
$this->assertEqualSetsWithIndex( $expected, $actual );
}

public function test_merge_incoming_data_color_presets_with_same_slugs_as_default_are_not_removed_if_defaults_are_disabled() {
$defaults = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'defaultPalette' => true, // Emulate the defaults from core theme.json.
'palette' => array(
array(
'slug' => 'red',
'color' => 'red',
'name' => 'Red',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Green',
),
),
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
'palette' => array(
array(
'slug' => 'blue',
'color' => 'blue',
'name' => 'Blue',
),
),
),
),
),
),
),
'default'
);
$theme = new WP_Theme_JSON(
array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'defaultPalette' => false,
'palette' => array(
array(
'slug' => 'pink',
'color' => 'pink',
'name' => 'Pink',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Greenish',
),
),
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
'palette' => array(
array(
'slug' => 'blue',
'color' => 'blue',
'name' => 'Bluish',
),
array(
'slug' => 'yellow',
'color' => 'yellow',
'name' => 'Yellow',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Block Green',
),
),
),
),
),
),
)
);

$expected = array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'defaultPalette' => false,
'palette' => array(
'default' => array(
array(
'slug' => 'red',
'color' => 'red',
'name' => 'Red',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Green',
),
),
'theme' => array(
array(
'slug' => 'pink',
'color' => 'pink',
'name' => 'Pink',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Greenish',
),
),
),
),
'blocks' => array(
'core/paragraph' => array(
'color' => array(
'palette' => array(
'default' => array(
array(
'slug' => 'blue',
'color' => 'blue',
'name' => 'Blue',
),
),
'theme' => array(
array(
'slug' => 'blue',
'color' => 'blue',
'name' => 'Bluish',
),
array(
'slug' => 'yellow',
'color' => 'yellow',
'name' => 'Yellow',
),
array(
'slug' => 'green',
'color' => 'green',
'name' => 'Block Green',
),
),
),
),
),
),
),
);

$defaults->merge( $theme );
$actual = $defaults->get_raw_data();

$this->assertEqualSetsWithIndex( $expected, $actual );
}

/**
* @ticket 54336
*/
Expand Down

0 comments on commit 16d6c97

Please sign in to comment.