diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/tests/block-supports/spacing.php | 138 | ||||
-rw-r--r-- | tests/phpunit/tests/rest-api/rest-settings-controller.php | 1 | ||||
-rw-r--r-- | tests/phpunit/tests/theme/wpThemeJson.php | 52 | ||||
-rw-r--r-- | tests/qunit/fixtures/wp-api-generated.js | 20 |
4 files changed, 58 insertions, 153 deletions
diff --git a/tests/phpunit/tests/block-supports/spacing.php b/tests/phpunit/tests/block-supports/spacing.php deleted file mode 100644 index 9215716708..0000000000 --- a/tests/phpunit/tests/block-supports/spacing.php +++ /dev/null @@ -1,138 +0,0 @@ -<?php -/** - * @group block-supports - */ -class Tests_Block_Supports_Spacing extends WP_UnitTestCase { - private $sample_block_content = '<div class="wp-block-test-block">Test</div>'; - private $test_gap_block_value = array(); - private $test_gap_block_args = array(); - - function set_up() { - parent::set_up(); - - $this->test_gap_block_value = array( - 'blockName' => 'test/test-block', - 'attrs' => array( - 'style' => array( - 'spacing' => array( - 'blockGap' => '3em', - ), - ), - ), - ); - - $this->test_gap_block_args = array( - 'api_version' => 2, - 'supports' => array( - 'spacing' => array( - 'blockGap' => true, - ), - ), - ); - } - - function tear_down() { - unregister_block_type( 'test/test-block' ); - - parent::tear_down(); - } - - function test_spacing_gap_block_support_renders_block_inline_style() { - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - $this->sample_block_content, - $this->test_gap_block_value - ); - - $this->assertSame( - '<div style="--wp--style--block-gap: 3em" class="wp-block-test-block">Test</div>', - $render_output - ); - } - - function test_spacing_gap_block_support_renders_block_inline_style_with_inner_tag() { - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - '<div class="wp-test-block"><p style="color: red;">Test</p></div>', - $this->test_gap_block_value - ); - - $this->assertSame( - '<div style="--wp--style--block-gap: 3em" class="wp-test-block"><p style="color: red;">Test</p></div>', - $render_output - ); - } - - function test_spacing_gap_block_support_renders_block_inline_style_with_no_other_attributes() { - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - '<div><p>Test</p></div>', - $this->test_gap_block_value - ); - - $this->assertSame( - '<div style="--wp--style--block-gap: 3em"><p>Test</p></div>', - $render_output - ); - } - - function test_spacing_gap_block_support_renders_appended_block_inline_style() { - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - '<div class="wp-test-block" style="background: green;"><p style="color: red;">Test</p></div>', - $this->test_gap_block_value - ); - - $this->assertSame( - '<div class="wp-test-block" style="--wp--style--block-gap: 3em; background: green;"><p style="color: red;">Test</p></div>', - $render_output - ); - } - - function test_spacing_gap_block_support_does_not_render_style_when_support_is_false() { - $this->test_gap_block_args['supports']['spacing']['blockGap'] = false; - - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - $this->sample_block_content, - $this->test_gap_block_value - ); - - $this->assertEquals( - $this->sample_block_content, - $render_output - ); - } - - function test_spacing_gap_block_support_does_not_render_style_when_gap_is_null() { - $this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = null; - $this->test_gap_block_args['supports']['spacing']['blockGap'] = true; - - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - $this->sample_block_content, - $this->test_gap_block_value - ); - - $this->assertEquals( - $this->sample_block_content, - $render_output - ); - } - - function test_spacing_gap_block_support_does_not_render_style_when_gap_is_illegal_value() { - $this->test_gap_block_value['attrs']['style']['spacing']['blockGap'] = '" javascript="alert("hello");'; - $this->test_gap_block_args['supports']['spacing']['blockGap'] = true; - - register_block_type( 'test/test-block', $this->test_gap_block_args ); - $render_output = wp_render_spacing_gap_support( - $this->sample_block_content, - $this->test_gap_block_value - ); - - $this->assertEquals( - $this->sample_block_content, - $render_output - ); - } -} diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index bb9a4bbdb6..fe99fccfa8 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -108,6 +108,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase 'posts_per_page', 'default_ping_status', 'default_comment_status', + 'site_icon', // Registered in wp-includes/blocks/site-logo.php ); if ( ! is_multisite() ) { diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index eefa1ca26a..6d92c3741b 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -419,18 +419,11 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 'spacing' => array( 'blockGap' => '1em', ), - 'blocks' => array( - 'core/columns' => array( - 'spacing' => array( - 'blockGap' => '24px', - ), - ), - ), ), ) ); - $expected = 'body { margin: 0; }body{--wp--style--block-gap: 1em;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }.wp-block-columns{--wp--style--block-gap: 24px;}'; + $expected = 'body { margin: 0; }body{--wp--style--block-gap: 1em;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-site-blocks > * { margin-top: 0; margin-bottom: 0; }.wp-site-blocks > * + * { margin-top: var( --wp--style--block-gap ); }'; $this->assertSame( $expected, $theme_json->get_stylesheet() ); $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) ); } @@ -2348,4 +2341,47 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] ); } + /** + * @ticket 54487 + */ + public function test_sanitization() { + $theme_json = new WP_Theme_JSON( + array( + 'version' => 2, + 'styles' => array( + 'spacing' => array( + 'blockGap' => 'valid value', + ), + 'blocks' => array( + 'core/group' => array( + 'spacing' => array( + 'margin' => 'valid value', + 'blockGap' => 'invalid value', + ), + ), + ), + ), + ) + ); + + $actual = $theme_json->get_raw_data(); + $expected = array( + 'version' => 2, + 'styles' => array( + 'spacing' => array( + 'blockGap' => 'valid value', + ), + 'blocks' => array( + 'core/group' => array( + 'spacing' => array( + 'margin' => 'valid value', + ), + ), + ), + ), + ); + + $this->assertEqualSetsWithIndex( $expected, $actual ); + } + } diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index c0b7b39ed2..8e3a7fb991 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -5035,7 +5035,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": true }, "theme": { @@ -5189,7 +5189,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": false }, "theme": { @@ -5503,7 +5503,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": false }, "theme": { @@ -5682,7 +5682,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": true }, "theme": { @@ -5841,7 +5841,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": false }, "theme": { @@ -6160,7 +6160,7 @@ mockedApiResponse.Schema = { "description": "Unique slug identifying the template.", "type": "string", "minLength": 1, - "pattern": "[a-zA-Z_\\-]+", + "pattern": "[a-zA-Z0-9_\\-]+", "required": false }, "theme": { @@ -9630,6 +9630,11 @@ mockedApiResponse.Schema = { "description": "Site logo.", "type": "integer", "required": false + }, + "site_icon": { + "description": "Site icon.", + "type": "integer", + "required": false } } } @@ -12212,5 +12217,6 @@ mockedApiResponse.settings = { "posts_per_page": 10, "default_ping_status": "open", "default_comment_status": "open", - "site_logo": null + "site_logo": null, + "site_icon": 0 }; |