Make WordPress Core


Ignore:
Timestamp:
02/20/2024 09:53:11 AM (3 years ago)
Author:
youknowriad
Message:

Tests: Synchronize Theme.JSON unit test between Core and Gutenberg.

Merges the changes from Core and Gutenberg for the following tests:

  • WP_REST_Global_Styles_Controller_Test
  • Tests_Theme_wpThemeJsonResolver
  • Tests_Theme_wpThemeJsonSchema
  • Tests_Theme_wpThemeJson

This will help ensure the stability of the theme.json style generation.

Props ajlende, scruffian, aaronrobertshaw, get_dave, youknowriad.
Fixes #60387.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r57260 r57662  
    2121
    2222        /**
     23         * WP_Theme_JSON_Resolver::$blocks_cache property.
     24         *
     25         * @var ReflectionProperty
     26         */
     27        private static $property_blocks_cache;
     28
     29        /**
     30         * Original value of the WP_Theme_JSON_Resolver::$blocks_cache property.
     31         *
     32         * @var array
     33         */
     34        private static $property_blocks_cache_orig_value;
     35
     36        /**
     37         * WP_Theme_JSON_Resolver::$core property.
     38         *
     39         * @var ReflectionProperty
     40         */
     41        private static $property_core;
     42
     43        /**
     44         * Original value of the WP_Theme_JSON_Resolver::$core property.
     45         *
     46         * @var WP_Theme_JSON
     47         */
     48        private static $property_core_orig_value;
     49
     50        /**
    2351         * Theme root directory.
    2452         *
    25          * @var string
     53         * @var string|null
    2654         */
    2755        private $theme_root;
    … …  
    3058         * Original theme directory.
    3159         *
    32          * @var string
     60         * @var array|null
    3361         */
    3462        private $orig_theme_dir;
    3563
    3664        /**
    37          * WP_Theme_JSON_Resolver::$blocks_cache property.
    38          *
    39          * @var ReflectionProperty
    40          */
    41         private static $property_blocks_cache;
    42 
    43         /**
    44          * Original value of the WP_Theme_JSON_Resolver::$blocks_cache property.
    45          *
    46          * @var array
    47          */
    48         private static $property_blocks_cache_orig_value;
    49 
    50         /**
    51          * WP_Theme_JSON_Resolver::$core property.
    52          *
    53          * @var ReflectionProperty
    54          */
    55         private static $property_core;
    56 
    57         /**
    58          * Original value of the WP_Theme_JSON_Resolver::$core property.
    59          *
    60          * @var WP_Theme_JSON
    61          */
    62         private static $property_core_orig_value;
     65         * @var array|null
     66         */
     67        private $queries;
    6368
    6469        public static function set_up_before_class() {
    … …  
    99104                add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) );
    100105                add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
    101 
     106                $this->queries = array();
    102107                // Clear caches.
    103108                wp_clean_themes_cache();
    … …  
    141146                $this->assertSame( 'block-theme', wp_get_theme()->get( 'TextDomain' ) );
    142147                $this->assertSame( 'Motyw blokowy', $theme_data->get_data()['title'] );
    143                 $this->assertSameSets(
     148                $this->assertSame(
    144149                        array(
    145150                                'color'      => array(
    … …  
    219224                $this->assertArrayHasKey( 'page-home', $custom_templates );
    220225                $this->assertSame(
    221                         $custom_templates['page-home'],
    222226                        array(
    223227                                'title'     => 'Szablon strony głównej',
    224228                                'postTypes' => array( 'page' ),
    225                         )
    226                 );
     229                        ),
     230                        $custom_templates['page-home']
     231                );
     232
    227233                $this->assertSameSets(
    228234                        array(
    … …  
    234240                        $theme_data->get_template_parts()
    235241                );
     242
    236243                $this->assertSame(
    237244                        'Wariant motywu blokowego',
    238                         $style_variations[1]['title']
     245                        $style_variations[2]['title']
    239246                );
    240247        }
    … …  
    258265
    259266        /**
    260          * Tests when WP_Theme_JSON_Resolver::$blocks_cache is empty or does not match
    261          * the all registered blocks.
     267         * Tests when WP_Theme_JSON_Resolver::$blocks_cache is empty or
     268         * does not match the all registered blocks.
    262269         *
    263270         * Though this is a non-public method, it is vital to other functionality.
    … …  
    332339
    333340        /**
    334          * Tests when WP_Theme_JSON_Resolver::$blocks_cache is empty or does not match
    335          * the all registered blocks.
     341         * Tests when WP_Theme_JSON_Resolver::$blocks_cache is empty or
     342         * does not match the all registered blocks.
    336343         *
    337344         * Though this is a non-public method, it is vital to other functionality.
    … …  
    597604
    598605                $this->assertSame(
    599                         WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(),
    600606                        array(
    601607                                'page-home'                   => array(
    … …  
    607613                                        'postTypes' => array( 'post' ),
    608614                                ),
    609                         )
     615                        ),
     616                        WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates()
    610617                );
    611618        }
    … …  
    750757         */
    751758        public function test_get_theme_data_theme_supports_overrides_theme_json() {
     759                switch_theme( 'default' );
     760
    752761                // Test that get_theme_data() returns a WP_Theme_JSON object.
    753762                $theme_json_resolver = new WP_Theme_JSON_Resolver();
    … …  
    763772                $previous_line_height = $previous_settings['typography']['lineHeight'];
    764773                $this->assertFalse( $previous_line_height, 'lineHeight setting from theme.json should be false.' );
     774
    765775                add_theme_support( 'custom-line-height' );
    766776                $current_settings = $theme_json_resolver->get_theme_data()->get_settings();
    767777                $line_height      = $current_settings['typography']['lineHeight'];
    768778                $this->assertTrue( $line_height, 'lineHeight setting after add_theme_support() should be true.' );
     779                remove_theme_support( 'custom-line-height' );
    769780        }
    770781
    … …  
    810821         * @param bool   $theme_palette      Whether the theme palette is present.
    811822         * @param string $theme_palette_text Message.
    812          * @param bool   $user_palette        Whether the user palette is present.
    813          * @param string $user_palette_text   Message.
     823         * @param bool   $user_palette       Whether the user palette is present.
     824         * @param string $user_palette_text  Message.
    814825         */
    815826        public function test_get_merged_data_returns_origin( $origin, $core_palette, $core_palette_text, $block_styles, $block_styles_text, $theme_palette, $theme_palette_text, $user_palette, $user_palette_text ) {
    … …  
    818829                        'my/block-with-styles',
    819830                        array(
    820                                 'api_version' => 2,
     831                                'api_version' => 3,
    821832                                'attributes'  => array(
    822833                                        'borderColor' => array(
    … …  
    878889         *
    879890         * @covers WP_Theme_JSON_Resolver::get_merged_data
    880          *
    881891         */
    882892        public function test_get_merged_data_returns_origin_proper() {
    … …  
    915925
    916926        /**
    917          * Data provider.
     927         * Data provider for test_get_merged_data_returns_origin.
    918928         *
    919929         * @return array[]
    … …  
    984994                $expected_settings = array(
    985995                        array(
    986                                 'version'  => 2,
     996                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     997                                'title'    => 'variation-a',
     998                                'settings' => array(
     999                                        'blocks' => array(
     1000                                                'core/paragraph' => array(
     1001                                                        'color' => array(
     1002                                                                'palette' => array(
     1003                                                                        'theme' => array(
     1004                                                                                array(
     1005                                                                                        'slug'  => 'dark',
     1006                                                                                        'name'  => 'Dark',
     1007                                                                                        'color' => '#010101',
     1008                                                                                ),
     1009                                                                        ),
     1010                                                                ),
     1011                                                        ),
     1012                                                ),
     1013                                        ),
     1014                                ),
     1015                        ),
     1016                        array(
     1017                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
    9871018                                'title'    => 'variation-b',
    9881019                                'settings' => array(
    … …  
    10051036                        ),
    10061037                        array(
    1007                                 'version'  => 2,
     1038                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
    10081039                                'title'    => 'Block theme variation',
    10091040                                'settings' => array(
Note: See TracChangeset for help on using the changeset viewer.