Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 11, 2021
1 parent d176efa commit 727c8b1
Showing 1 changed file with 78 additions and 74 deletions.
152 changes: 78 additions & 74 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase {
function test_user_data_is_escaped() {
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'styles' => array(
'styles' => array(
'global' => array(
'color' => array(
'background' => 'green',
'gradient' => 'linear-gradient(10deg,rgba(6,147,227,1) 0%,rgb(61,132,163) 37%,rgb(155,81,224) 100%)',
Expand All @@ -27,8 +27,8 @@ function test_user_data_is_escaped() {
$result = $theme_json->get_raw_data();

$expected = array(
'global' => array(
'styles' => array(
'styles' => array(
'global' => array(
'color' => array(
'background' => 'green',
'gradient' => 'linear-gradient(10deg,rgba(6,147,227,1) 0%,rgb(61,132,163) 37%,rgb(155,81,224) 100%)',
Expand All @@ -44,15 +44,13 @@ function test_user_data_is_escaped() {
function test_contexts_not_valid_are_skipped() {
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'false',
),
),
),
'core/invalid' => array(
'settings' => array(
'core/invalid' => array(
'color' => array(
'custom' => 'false',
),
Expand All @@ -63,8 +61,8 @@ function test_contexts_not_valid_are_skipped() {
$result = $theme_json->get_raw_data();

$expected = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'false',
),
Expand All @@ -78,9 +76,9 @@ function test_contexts_not_valid_are_skipped() {
function test_properties_not_valid_are_skipped() {
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'invalidKey' => 'invalid value',
'settings' => array(
'invalidKey' => 'invalid value',
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'false',
'invalidKey' => 'invalid value',
Expand All @@ -89,28 +87,32 @@ function test_properties_not_valid_are_skipped() {
'invalidKey' => 'invalid value',
),
),
'styles' => array(
),
'styles' => array(
'global' => array(
'typography' => array(
'fontSize' => '12',
'invalidProperty' => 'invalid value',
),
'invalidSection' => array(
'invalidProperty' => 'invalid value',
),
),
)
),
)
);
$result = $theme_json->get_raw_data();

$expected = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'false',
),
),
'styles' => array(
),
'styles' => array(
'global' => array(
'typography' => array(
'fontSize' => '12',
),
Expand All @@ -125,21 +127,23 @@ function test_get_settings() {
// See schema at WP_Theme_JSON::SCHEMA.
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'link' => 'value',
),
'custom' => 'value',
'typography' => 'value',
'misc' => 'value',
),
'styles' => array(
),
'styles' => array(
'global' => array(
'color' => 'value',
'misc' => 'value',
),
'misc' => 'value',
)
),
'misc' => 'value',
)
);

Expand All @@ -157,8 +161,8 @@ function test_get_stylesheet() {
// See schema at WP_Theme_JSON::SCHEMA.
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'text' => 'value',
'palette' => array(
Expand All @@ -182,17 +186,16 @@ function test_get_stylesheet() {
),
'misc' => 'value',
),
'styles' => array(
),
'styles' => array(
'global' => array(
'color' => array(
'link' => '#111',
'text' => 'var:preset|color|grey',
),
'misc' => 'value',
),
'misc' => 'value',
),
'core/group' => array(
'styles' => array(
'core/group' => array(
'spacing' => array(
'padding' => array(
'top' => '12px',
Expand All @@ -201,6 +204,7 @@ function test_get_stylesheet() {
),
),
),
'misc' => 'value',
)
);

Expand All @@ -220,8 +224,8 @@ function test_get_stylesheet() {

public function test_merge_incoming_data() {
$initial = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'false',
'palette' => array(
Expand All @@ -236,29 +240,31 @@ public function test_merge_incoming_data() {
),
),
),
'styles' => array(
'typography' => array(
'fontSize' => '12',
),
),
),
'core/paragraph' => array(
'settings' => array(
'core/paragraph' => array(
'color' => array(
'custom' => 'false',
),
),
),
'styles' => array(
'global' => array(
'typography' => array(
'fontSize' => '12',
),
)
),
);

$add_new_context = array(
'core/list' => array(
'settings' => array(
'settings' => array(
'core/list' => array(
'color' => array(
'custom' => 'false',
),
),
'styles' => array(
),
'styles' => array(
'core/list' => array(
'typography' => array(
'fontSize' => '12',
),
Expand All @@ -271,8 +277,8 @@ public function test_merge_incoming_data() {
);

$add_key_in_settings = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'customGradient' => 'true',
),
Expand All @@ -281,8 +287,8 @@ public function test_merge_incoming_data() {
);

$update_key_in_settings = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'true',
),
Expand All @@ -291,8 +297,8 @@ public function test_merge_incoming_data() {
);

$add_styles = array(
'core/paragraph' => array(
'styles' => array(
'styles' => array(
'core/paragraph' => array(
'typography' => array(
'fontSize' => '12',
),
Expand All @@ -304,8 +310,8 @@ public function test_merge_incoming_data() {
);

$add_key_in_styles = array(
'core/paragraph' => array(
'styles' => array(
'styles' => array(
'core/paragraph' => array(
'typography' => array(
'lineHeight' => '12',
),
Expand All @@ -314,8 +320,8 @@ public function test_merge_incoming_data() {
);

$add_invalid_context = array(
'core/para' => array(
'styles' => array(
'styles' => array(
'core/para' => array(
'typography' => array(
'lineHeight' => '12',
),
Expand All @@ -324,8 +330,8 @@ public function test_merge_incoming_data() {
);

$update_presets = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'palette' => array(
array(
Expand Down Expand Up @@ -359,8 +365,8 @@ public function test_merge_incoming_data() {
);

$expected = array(
'global' => array(
'settings' => array(
'settings' => array(
'global' => array(
'color' => array(
'custom' => 'true',
'customGradient' => 'true',
Expand Down Expand Up @@ -392,19 +398,24 @@ public function test_merge_incoming_data() {
),
),
),
'styles' => array(
'typography' => array(
'fontSize' => '12',
'core/paragraph' => array(
'color' => array(
'custom' => 'false',
),
),
),
'core/paragraph' => array(
'settings' => array(
'core/list' => array(
'color' => array(
'custom' => 'false',
),
),
'styles' => array(
),
'styles' => array(
'global' => array(
'typography' => array(
'fontSize' => '12',
),
),
'core/paragraph' => array(
'typography' => array(
'fontSize' => '12',
'lineHeight' => '12',
Expand All @@ -413,22 +424,15 @@ public function test_merge_incoming_data() {
'link' => 'pink',
),
),
),
'core/list' => array(
'settings' => array(
'color' => array(
'custom' => 'false',
),
),
'styles' => array(
'core/list' => array(
'typography' => array(
'fontSize' => '12',
),
'color' => array(
'link' => 'pink',
'background' => 'brown',
),
),
)
),
);

Expand Down

0 comments on commit 727c8b1

Please sign in to comment.