Make WordPress Core


Ignore:
Timestamp:
11/08/2021 07:18:39 PM (2 years ago)
Author:
jorgefilipecosta
Message:

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.

File:
1 edited

Legend:

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

    r51599 r52049  
    4747    /**
    4848     * @ticket 52991
     49     * @ticket 54336
    4950     */
    5051    public function test_translations_are_applied() {
     
    5354
    5455        switch_theme( 'block-theme' );
    55 
    5656        $actual = WP_Theme_JSON_Resolver::get_theme_data();
    5757
     
    6363            array(
    6464                'color'      => array(
     65                    'custom'         => false,
     66                    'customGradient' => false,
    6567                    'palette'        => array(
    6668                        'theme' => array(
     
    8688                        ),
    8789                    ),
    88                     'custom'         => false,
    89                     'customGradient' => false,
    9090                ),
    9191                'typography' => array(
    92                     'fontSizes'        => array(
     92                    'customFontSize' => false,
     93                    'lineHeight'     => true,
     94                    'fontSizes'      => array(
    9395                        'theme' => array(
    9496                            array(
     
    99101                        ),
    100102                    ),
    101                     'customFontSize'   => false,
    102                     'customLineHeight' => true,
    103103                ),
    104104                'spacing'    => array(
    105                     'units'         => array(
    106                         'rem',
    107                     ),
    108                     'customPadding' => true,
     105                    'units'   => array( 'rem' ),
     106                    'padding' => true,
    109107                ),
    110108                'blocks'     => array(
     
    126124            $actual->get_settings()
    127125        );
     126        $this->assertSame(
     127            $actual->get_custom_templates(),
     128            array(
     129                'page-home' => array(
     130                    'title'     => 'Szablon strony głównej',
     131                    'postTypes' => array( 'page' ),
     132                ),
     133            )
     134        );
     135        $this->assertSame(
     136            $actual->get_template_parts(),
     137            array(
     138                'small-header' => array(
     139                    'title' => 'Mały nagłówek',
     140                    'area'  => 'header',
     141                ),
     142            )
     143        );
    128144    }
    129145
     
    144160    }
    145161
     162    /**
     163     * @ticket 54336
     164     */
     165    function test_add_theme_supports_are_loaded_for_themes_without_theme_json() {
     166        switch_theme( 'default' );
     167        $color_palette = array(
     168            array(
     169                'name'  => 'Primary',
     170                'slug'  => 'primary',
     171                'color' => '#F00',
     172            ),
     173            array(
     174                'name'  => 'Secondary',
     175                'slug'  => 'secondary',
     176                'color' => '#0F0',
     177            ),
     178            array(
     179                'name'  => 'Tertiary',
     180                'slug'  => 'tertiary',
     181                'color' => '#00F',
     182            ),
     183        );
     184        add_theme_support( 'editor-color-palette', $color_palette );
     185        add_theme_support( 'custom-line-height' );
     186
     187        $settings = WP_Theme_JSON_Resolver::get_theme_data()->get_settings();
     188
     189        remove_theme_support( 'custom-line-height' );
     190        remove_theme_support( 'editor-color-palette' );
     191
     192        $this->assertFalse( WP_Theme_JSON_Resolver::theme_has_support() );
     193        $this->assertTrue( $settings['typography']['lineHeight'] );
     194        $this->assertSame( $color_palette, $settings['color']['palette']['theme'] );
     195    }
     196
     197    /**
     198     * Recursively applies ksort to an array.
     199     */
     200    private static function recursive_ksort( &$array ) {
     201        foreach ( $array as &$value ) {
     202            if ( is_array( $value ) ) {
     203                self::recursive_ksort( $value );
     204            }
     205        }
     206        ksort( $array );
     207    }
     208
     209    /**
     210     * @ticket 54336
     211     */
     212    function test_merges_child_theme_json_into_parent_theme_json() {
     213        switch_theme( 'block-theme-child' );
     214
     215        $actual_settings   = WP_Theme_JSON_Resolver::get_theme_data()->get_settings();
     216        $expected_settings = array(
     217            'color'      => array(
     218                'custom'         => false,
     219                'customGradient' => false,
     220                'gradients'      => array(
     221                    'theme' => array(
     222                        array(
     223                            'name'     => 'Custom gradient',
     224                            'gradient' => 'linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)',
     225                            'slug'     => 'custom-gradient',
     226                        ),
     227                    ),
     228                ),
     229                'palette'        => array(
     230                    'theme' => array(
     231                        array(
     232                            'slug'  => 'light',
     233                            'name'  => 'Light',
     234                            'color' => '#f3f4f6',
     235                        ),
     236                        array(
     237                            'slug'  => 'primary',
     238                            'name'  => 'Primary',
     239                            'color' => '#3858e9',
     240                        ),
     241                        array(
     242                            'slug'  => 'dark',
     243                            'name'  => 'Dark',
     244                            'color' => '#111827',
     245                        ),
     246                    ),
     247                ),
     248                'link'           => true,
     249            ),
     250            'typography' => array(
     251                'customFontSize' => false,
     252                'lineHeight'     => true,
     253                'fontSizes'      => array(
     254                    'theme' => array(
     255                        array(
     256                            'name' => 'Custom',
     257                            'slug' => 'custom',
     258                            'size' => '100px',
     259                        ),
     260                    ),
     261                ),
     262            ),
     263            'spacing'    => array(
     264                'units'   => array( 'rem' ),
     265                'padding' => true,
     266            ),
     267            'blocks'     => array(
     268                'core/paragraph'  => array(
     269                    'color' => array(
     270                        'palette' => array(
     271                            'theme' => array(
     272                                array(
     273                                    'slug'  => 'light',
     274                                    'name'  => 'Light',
     275                                    'color' => '#f5f7f9',
     276                                ),
     277                            ),
     278                        ),
     279                    ),
     280                ),
     281                'core/post-title' => array(
     282                    'color' => array(
     283                        'palette' => array(
     284                            'theme' => array(
     285                                array(
     286                                    'slug'  => 'light',
     287                                    'name'  => 'Light',
     288                                    'color' => '#f3f4f6',
     289                                ),
     290                            ),
     291                        ),
     292                    ),
     293                ),
     294            ),
     295        );
     296        self::recursive_ksort( $actual_settings );
     297        self::recursive_ksort( $expected_settings );
     298
     299        // Should merge settings.
     300        $this->assertSame(
     301            $expected_settings,
     302            $actual_settings
     303        );
     304
     305        $this->assertSame(
     306            WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(),
     307            array(
     308                'page-home' => array(
     309                    'title'     => 'Homepage',
     310                    'postTypes' => array( 'page' ),
     311                ),
     312            )
     313        );
     314    }
    146315}
Note: See TracChangeset for help on using the changeset viewer.