mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 09:10:06 +00:00
Update theme.json classes for WordPress 5.9.
This commit ports to core the changes to the classes that deal with theme.json code. See #54336. Props oandregal, spacedmonkey, noisysocks, hellofromtonya, youknowriad. git-svn-id: https://develop.svn.wordpress.org/trunk@52049 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -22,6 +22,10 @@ msgctxt "Custom template name"
|
||||
msgid "Homepage template"
|
||||
msgstr "Szablon strony głównej"
|
||||
|
||||
msgctxt "Template part name"
|
||||
msgid "Small Header"
|
||||
msgstr "Mały nagłówek"
|
||||
|
||||
msgctxt "Color name"
|
||||
msgid "Light"
|
||||
msgstr "Jasny"
|
||||
|
||||
8
tests/phpunit/data/themedir1/block-theme-child/style.css
Normal file
8
tests/phpunit/data/themedir1/block-theme-child/style.css
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Theme Name: Block Theme Child Theme
|
||||
Theme URI: https://wordpress.org/
|
||||
Description: For testing purposes only.
|
||||
Template: block-theme
|
||||
Version: 1.0.0
|
||||
Text Domain: block-theme-child
|
||||
*/
|
||||
51
tests/phpunit/data/themedir1/block-theme-child/theme.json
Normal file
51
tests/phpunit/data/themedir1/block-theme-child/theme.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"version": 1,
|
||||
"settings": {
|
||||
"color": {
|
||||
"palette": [
|
||||
{
|
||||
"slug": "light",
|
||||
"name": "Light",
|
||||
"color": "#f3f4f6"
|
||||
},
|
||||
{
|
||||
"slug": "primary",
|
||||
"name": "Primary",
|
||||
"color": "#3858e9"
|
||||
},
|
||||
{
|
||||
"slug": "dark",
|
||||
"name": "Dark",
|
||||
"color": "#111827"
|
||||
}
|
||||
],
|
||||
"link": true
|
||||
},
|
||||
"blocks": {
|
||||
"core/post-title": {
|
||||
"color": {
|
||||
"palette": [
|
||||
{
|
||||
"slug": "light",
|
||||
"name": "Light",
|
||||
"color": "#f3f4f6"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"customTemplates": [
|
||||
{
|
||||
"name": "page-home",
|
||||
"title": "Homepage"
|
||||
}
|
||||
],
|
||||
"templateParts": [
|
||||
{
|
||||
"name": "small-header",
|
||||
"title": "Small Header",
|
||||
"area": "header"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -64,6 +64,7 @@
|
||||
"templateParts": [
|
||||
{
|
||||
"name": "small-header",
|
||||
"title": "Small Header",
|
||||
"area": "header"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -162,6 +162,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
|
||||
'camelCase',
|
||||
'REST Theme',
|
||||
'Block Theme',
|
||||
'Block Theme Child Theme',
|
||||
);
|
||||
|
||||
sort( $theme_names );
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -46,13 +46,13 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 52991
|
||||
* @ticket 54336
|
||||
*/
|
||||
public function test_translations_are_applied() {
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
|
||||
load_textdomain( 'block-theme', realpath( DIR_TESTDATA . '/languages/themes/block-theme-pl_PL.mo' ) );
|
||||
|
||||
switch_theme( 'block-theme' );
|
||||
|
||||
$actual = WP_Theme_JSON_Resolver::get_theme_data();
|
||||
|
||||
unload_textdomain( 'block-theme' );
|
||||
@@ -62,6 +62,8 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
$this->assertSame(
|
||||
array(
|
||||
'color' => array(
|
||||
'custom' => false,
|
||||
'customGradient' => false,
|
||||
'palette' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
@@ -85,11 +87,11 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
),
|
||||
'custom' => false,
|
||||
'customGradient' => false,
|
||||
),
|
||||
'typography' => array(
|
||||
'fontSizes' => array(
|
||||
'customFontSize' => false,
|
||||
'lineHeight' => true,
|
||||
'fontSizes' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'name' => 'Custom',
|
||||
@@ -98,14 +100,10 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
),
|
||||
),
|
||||
'customFontSize' => false,
|
||||
'customLineHeight' => true,
|
||||
),
|
||||
'spacing' => array(
|
||||
'units' => array(
|
||||
'rem',
|
||||
),
|
||||
'customPadding' => true,
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
@@ -125,6 +123,24 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
),
|
||||
$actual->get_settings()
|
||||
);
|
||||
$this->assertSame(
|
||||
$actual->get_custom_templates(),
|
||||
array(
|
||||
'page-home' => array(
|
||||
'title' => 'Szablon strony głównej',
|
||||
'postTypes' => array( 'page' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertSame(
|
||||
$actual->get_template_parts(),
|
||||
array(
|
||||
'small-header' => array(
|
||||
'title' => 'Mały nagłówek',
|
||||
'area' => 'header',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,4 +159,157 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
$this->assertTrue( $has_theme_json_support );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 54336
|
||||
*/
|
||||
function test_add_theme_supports_are_loaded_for_themes_without_theme_json() {
|
||||
switch_theme( 'default' );
|
||||
$color_palette = array(
|
||||
array(
|
||||
'name' => 'Primary',
|
||||
'slug' => 'primary',
|
||||
'color' => '#F00',
|
||||
),
|
||||
array(
|
||||
'name' => 'Secondary',
|
||||
'slug' => 'secondary',
|
||||
'color' => '#0F0',
|
||||
),
|
||||
array(
|
||||
'name' => 'Tertiary',
|
||||
'slug' => 'tertiary',
|
||||
'color' => '#00F',
|
||||
),
|
||||
);
|
||||
add_theme_support( 'editor-color-palette', $color_palette );
|
||||
add_theme_support( 'custom-line-height' );
|
||||
|
||||
$settings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings();
|
||||
|
||||
remove_theme_support( 'custom-line-height' );
|
||||
remove_theme_support( 'editor-color-palette' );
|
||||
|
||||
$this->assertFalse( WP_Theme_JSON_Resolver::theme_has_support() );
|
||||
$this->assertTrue( $settings['typography']['lineHeight'] );
|
||||
$this->assertSame( $color_palette, $settings['color']['palette']['theme'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively applies ksort to an array.
|
||||
*/
|
||||
private static function recursive_ksort( &$array ) {
|
||||
foreach ( $array as &$value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
self::recursive_ksort( $value );
|
||||
}
|
||||
}
|
||||
ksort( $array );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 54336
|
||||
*/
|
||||
function test_merges_child_theme_json_into_parent_theme_json() {
|
||||
switch_theme( 'block-theme-child' );
|
||||
|
||||
$actual_settings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings();
|
||||
$expected_settings = array(
|
||||
'color' => array(
|
||||
'custom' => false,
|
||||
'customGradient' => false,
|
||||
'gradients' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'name' => 'Custom gradient',
|
||||
'gradient' => 'linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)',
|
||||
'slug' => 'custom-gradient',
|
||||
),
|
||||
),
|
||||
),
|
||||
'palette' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'slug' => 'light',
|
||||
'name' => 'Light',
|
||||
'color' => '#f3f4f6',
|
||||
),
|
||||
array(
|
||||
'slug' => 'primary',
|
||||
'name' => 'Primary',
|
||||
'color' => '#3858e9',
|
||||
),
|
||||
array(
|
||||
'slug' => 'dark',
|
||||
'name' => 'Dark',
|
||||
'color' => '#111827',
|
||||
),
|
||||
),
|
||||
),
|
||||
'link' => true,
|
||||
),
|
||||
'typography' => array(
|
||||
'customFontSize' => false,
|
||||
'lineHeight' => true,
|
||||
'fontSizes' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'name' => 'Custom',
|
||||
'slug' => 'custom',
|
||||
'size' => '100px',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacing' => array(
|
||||
'units' => array( 'rem' ),
|
||||
'padding' => true,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/paragraph' => array(
|
||||
'color' => array(
|
||||
'palette' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'slug' => 'light',
|
||||
'name' => 'Light',
|
||||
'color' => '#f5f7f9',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'core/post-title' => array(
|
||||
'color' => array(
|
||||
'palette' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'slug' => 'light',
|
||||
'name' => 'Light',
|
||||
'color' => '#f3f4f6',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
self::recursive_ksort( $actual_settings );
|
||||
self::recursive_ksort( $expected_settings );
|
||||
|
||||
// Should merge settings.
|
||||
$this->assertSame(
|
||||
$expected_settings,
|
||||
$actual_settings
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(),
|
||||
array(
|
||||
'page-home' => array(
|
||||
'title' => 'Homepage',
|
||||
'postTypes' => array( 'page' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
193
tests/phpunit/tests/theme/wpThemeJsonSchema.php
Normal file
193
tests/phpunit/tests/theme/wpThemeJsonSchema.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test WP_Theme_JSON_Schema class.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Theme
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @group themes
|
||||
*/
|
||||
class Tests_Theme_wpThemeJsonSchema extends WP_UnitTestCase {
|
||||
/**
|
||||
* The current theme.json schema version.
|
||||
*/
|
||||
const LATEST_SCHEMA_VERSION = WP_Theme_JSON::LATEST_SCHEMA;
|
||||
|
||||
/**
|
||||
* @ticket 54336
|
||||
*/
|
||||
function test_migrate_v1_to_v2() {
|
||||
$theme_json_v1 = array(
|
||||
'version' => 1,
|
||||
'settings' => array(
|
||||
'color' => array(
|
||||
'palette' => array(
|
||||
array(
|
||||
'name' => 'Pale Pink',
|
||||
'slug' => 'pale-pink',
|
||||
'color' => '#f78da7',
|
||||
),
|
||||
array(
|
||||
'name' => 'Vivid Red',
|
||||
'slug' => 'vivid-red',
|
||||
'color' => '#cf2e2e',
|
||||
),
|
||||
),
|
||||
'custom' => false,
|
||||
'link' => true,
|
||||
),
|
||||
'border' => array(
|
||||
'color' => false,
|
||||
'customRadius' => false,
|
||||
'style' => false,
|
||||
'width' => false,
|
||||
),
|
||||
'typography' => array(
|
||||
'fontStyle' => false,
|
||||
'fontWeight' => false,
|
||||
'letterSpacing' => false,
|
||||
'textDecoration' => false,
|
||||
'textTransform' => false,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/group' => array(
|
||||
'border' => array(
|
||||
'color' => true,
|
||||
'customRadius' => true,
|
||||
'style' => true,
|
||||
'width' => true,
|
||||
),
|
||||
'typography' => array(
|
||||
'fontStyle' => true,
|
||||
'fontWeight' => true,
|
||||
'letterSpacing' => true,
|
||||
'textDecoration' => true,
|
||||
'textTransform' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'styles' => array(
|
||||
'color' => array(
|
||||
'background' => 'purple',
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/group' => array(
|
||||
'color' => array(
|
||||
'background' => 'red',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'top' => '10px',
|
||||
),
|
||||
),
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'yellow',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'red',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$actual = WP_Theme_JSON_Schema::migrate( $theme_json_v1 );
|
||||
|
||||
$expected = array(
|
||||
'version' => self::LATEST_SCHEMA_VERSION,
|
||||
'settings' => array(
|
||||
'color' => array(
|
||||
'palette' => array(
|
||||
array(
|
||||
'name' => 'Pale Pink',
|
||||
'slug' => 'pale-pink',
|
||||
'color' => '#f78da7',
|
||||
),
|
||||
array(
|
||||
'name' => 'Vivid Red',
|
||||
'slug' => 'vivid-red',
|
||||
'color' => '#cf2e2e',
|
||||
),
|
||||
),
|
||||
'custom' => false,
|
||||
'link' => true,
|
||||
),
|
||||
'border' => array(
|
||||
'color' => false,
|
||||
'radius' => false,
|
||||
'style' => false,
|
||||
'width' => false,
|
||||
),
|
||||
'typography' => array(
|
||||
'fontStyle' => false,
|
||||
'fontWeight' => false,
|
||||
'letterSpacing' => false,
|
||||
'textDecoration' => false,
|
||||
'textTransform' => false,
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/group' => array(
|
||||
'border' => array(
|
||||
'color' => true,
|
||||
'radius' => true,
|
||||
'style' => true,
|
||||
'width' => true,
|
||||
),
|
||||
'typography' => array(
|
||||
'fontStyle' => true,
|
||||
'fontWeight' => true,
|
||||
'letterSpacing' => true,
|
||||
'textDecoration' => true,
|
||||
'textTransform' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'styles' => array(
|
||||
'color' => array(
|
||||
'background' => 'purple',
|
||||
),
|
||||
'blocks' => array(
|
||||
'core/group' => array(
|
||||
'color' => array(
|
||||
'background' => 'red',
|
||||
),
|
||||
'spacing' => array(
|
||||
'padding' => array(
|
||||
'top' => '10px',
|
||||
),
|
||||
),
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'yellow',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'elements' => array(
|
||||
'link' => array(
|
||||
'color' => array(
|
||||
'text' => 'red',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user