Make WordPress Core

Ticket #56611: 56611.diff

File 56611.diff, 13.0 KB (added by johnregan3, 3 years ago)

New theme.json Unit Tests

  • tests/phpunit/data/themedir1/block-theme/theme.json

    diff --git tests/phpunit/data/themedir1/block-theme/theme.json tests/phpunit/data/themedir1/block-theme/theme.json
    index 4961a620a2..52bb194b4a 100644
     
    2222                                        "slug": "custom-gradient"
    2323                                }
    2424                        ],
     25                        "duotone": [
     26                                {
     27                                        "colors": [ "#333333", "#aaaaaa" ],
     28                                        "slug": "custom-duotone",
     29                                        "name": "Custom Duotone"
     30                                }
     31                        ],
    2532                        "custom": false,
    2633                        "customGradient": false
    2734                },
     
    3845                },
    3946                "spacing": {
    4047                        "units": ["rem"],
    41                         "customPadding": true
     48                        "customPadding": true,
     49                        "blockGap": true
    4250                },
    4351                "blocks": {
    4452                        "core/paragraph": {
     
    5462                        }
    5563                }
    5664        },
     65        "styles" : {
     66                "blocks" :{
     67                        "core/post-featured-image": {
     68                                "shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)",
     69                                "filter": {
     70                                        "duotone": "var(--wp--preset--duotone--custom-duotone)"
     71                                }
     72                        }
     73                },
     74                "elements": {
     75                        "button": {
     76                                "shadow": "10px 10px 5px 0px rgba(0,0,0,0.66)"
     77                        },
     78                        "link": {
     79                                "typography": {
     80                                        "textDecoration": "none"
     81                                },
     82                                "border": {
     83                                        "bottom": {
     84                                                "width": "2px",
     85                                                "color": "currentColor",
     86                                                "style": "solid"
     87                                        }
     88                                },
     89                                ":hover": {
     90                                        "typography": {
     91                                                "textDecoration": "none"
     92                                        },
     93                                        "border": {
     94                                                "bottom": {
     95                                                        "width": "2px",
     96                                                        "color": "#000",
     97                                                        "style": "dotted"
     98                                                }
     99                                        }
     100                                }
     101                        }
     102                }
     103        },
    57104        "customTemplates": [
    58105                {
    59106                        "name": "page-home",
  • tests/phpunit/tests/theme/wpThemeJson.php

    diff --git tests/phpunit/tests/theme/wpThemeJson.php tests/phpunit/tests/theme/wpThemeJson.php
    index 4cc81c98b2..7e7b439d97 100644
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    431431        /**
    432432         * @ticket 53175
    433433         * @ticket 54336
     434         * @ticket 56611
    434435         */
    435436        public function test_get_stylesheet() {
    436437                $theme_json = new WP_Theme_JSON(
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    438439                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
    439440                                'settings' => array(
    440441                                        'color'      => array(
    441                                                 'text'    => 'value',
    442                                                 'palette' => array(
     442                                                'text'      => 'value',
     443                                                'palette'   => array(
    443444                                                        array(
    444445                                                                'slug'  => 'grey',
    445446                                                                'color' => 'grey',
    446447                                                        ),
    447448                                                ),
     449                                                'gradients' => array(
     450                                                        array(
     451                                                                'gradient' => 'linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%)',
     452                                                                'name'     => 'Custom gradient',
     453                                                                'slug'     => 'custom-gradient',
     454                                                        ),
     455                                                ),
     456                                                'duotone'  => array(
     457                                                        array(
     458                                                                'colors' => array( '#333333', '#aaaaaa' ),
     459                                                                'name'   => 'Custom Duotone',
     460                                                                'slug'   => 'custom-duotone',
     461                                                        ),
     462                                                ),
    448463                                        ),
    449464                                        'typography' => array(
    450465                                                'fontFamilies' => array(
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    478493                                        ),
    479494                                        'misc'     => 'value',
    480495                                        'elements' => array(
    481                                                 'link' => array(
     496                                                'link'   => array(
    482497                                                        'color' => array(
    483498                                                                'text'       => '#111',
    484499                                                                'background' => '#333',
    485500                                                        ),
    486501                                                ),
     502                                                'button' => array(
     503                                                        'shadow' => '10px 10px 5px 0px rgba(0,0,0,0.66)',
     504                                                ),
    487505                                        ),
    488506                                        'blocks'   => array(
    489507                                                'core/group'     => array(
     508                                                        'color'    => array(
     509                                                                'gradient' => 'var:preset|gradient|custom-gradient',
     510                                                        ),
    490511                                                        'border'   => array(
    491512                                                                'radius' => '10px',
    492513                                                        ),
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    542563                                                                        'bottom' => '30px',
    543564                                                                ),
    544565                                                        ),
     566                                                        'filter'  => array(
     567                                                                'duotone' => 'var:preset|duotone|custom-duotone',
     568                                                        ),
    545569                                                ),
    546570                                        ),
    547571                                        'spacing'  => array(
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    552576                        )
    553577                );
    554578
    555                 $variables = 'body{--wp--preset--color--grey: grey;--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
    556                 $styles    = 'body { margin: 0; }.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; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}';
    557                 $presets   = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
     579                $variables = "body{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--duotone--custom-duotone: url('#wp-duotone-custom-duotone');--wp--preset--font-family--small: 14px;--wp--preset--font-family--big: 41px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}";
     580                $styles    = 'body { margin: 0; }.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; }body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}.wp-element-button, .wp-block-button__link{box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}.wp-block-group{background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;padding: 24px;}.wp-block-group a:where(:not(.wp-element-button)){color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button)){background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a:where(:not(.wp-element-button)){background-color: #777;color: #555;}.wp-block-image{margin-bottom: 30px;}.wp-block-image img, .wp-block-image .components-placeholder{filter: var(--wp--preset--duotone--custom-duotone);}.wp-block-image img, .wp-block-image .wp-block-image__crop-area{border-top-left-radius: 10px;border-bottom-right-radius: 1em;}';
     581                $presets   = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-family{font-family: var(--wp--preset--font-family--small) !important;}.has-big-font-family{font-family: var(--wp--preset--font-family--big) !important;}';
    558582                $all       = $variables . $styles . $presets;
    559583                $this->assertSame( $all, $theme_json->get_stylesheet() );
    560584                $this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    29452969                $this->assertEqualSetsWithIndex( $expected, $actual );
    29462970        }
    29472971
     2972        /**
     2973         * @ticket 56611
     2974         */
     2975        function test_export_data_sets_use_root_padding_aware_alignments() {
     2976                $theme = new WP_Theme_JSON(
     2977                        array(
     2978                                'version'  => 2,
     2979                                'settings' => array(
     2980                                        'useRootPaddingAwareAlignments' => true,
     2981                                        'blocks'          => array(
     2982                                                'core/paragraph' => array(
     2983                                                        'useRootPaddingAwareAlignments' => true,
     2984                                                ),
     2985                                        ),
     2986                                ),
     2987                        )
     2988                );
     2989
     2990                $actual   = $theme->get_data();
     2991                $expected = array(
     2992                        'version'  => 2,
     2993                        'settings' => array(
     2994                                'useRootPaddingAwareAlignments' => true,
     2995                                'blocks'          => array(
     2996                                        'core/paragraph' => array(
     2997                                                'useRootPaddingAwareAlignments' => true,
     2998                                        ),
     2999                                ),
     3000                        ),
     3001                );
     3002
     3003                $this->assertEqualSetsWithIndex( $expected, $actual );
     3004        }
     3005
     3006
    29483007        /**
    29493008         * @ticket 56467
    29503009         */
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    34203479                );
    34213480
    34223481                $metadata = array(
    3423                         'path'     => array(
    3424                                 '0' => 'styles',
    3425                         ),
     3482                        'path'     => array( 'styles' ),
    34263483                        'selector' => 'body',
    34273484                );
    34283485
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    34533510                );
    34543511
    34553512                $metadata = array(
    3456                         'path'     => array(
    3457                                 '0' => 'styles',
    3458                         ),
     3513                        'path'     => array( 'styles' ),
    34593514                        'selector' => 'body',
    34603515                );
    34613516
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    34823537                );
    34833538
    34843539                $metadata = array(
    3485                         'path'     => array(
    3486                                 '0' => 'settings',
    3487                         ),
     3540                        'path'     => array( 'settings' ),
    34883541                        'selector' => 'body',
    34893542                );
    34903543
    class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 
    34943547                $this->assertSame( $expected, $root_rules . $style_rules );
    34953548        }
    34963549
     3550        /**
     3551         * @ticket 56611
     3552         */
     3553        function test_get_styles_with_appearance_tools() {
     3554                $theme_json = new WP_Theme_JSON(
     3555                        array(
     3556                                'version'  => 2,
     3557                                'settings' => array(
     3558                                        'appearanceTools' => true,
     3559                                ),
     3560                        )
     3561                );
     3562
     3563                $metadata = array(
     3564                        'path'     => array( 'settings' ),
     3565                        'selector' => 'body',
     3566                );
     3567
     3568                $expected    = 'body { margin: 0; }.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-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: ; }body { --wp--style--block-gap: ; }';
     3569                $root_rules  = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
     3570                $this->assertSame( $expected, $root_rules);
     3571        }
     3572
    34973573        /**
    34983574         * Tests generating the spacing presets array based on the spacing scale provided.
    34993575         *
  • tests/phpunit/tests/theme/wpThemeJsonResolver.php

    diff --git tests/phpunit/tests/theme/wpThemeJsonResolver.php tests/phpunit/tests/theme/wpThemeJsonResolver.php
    index aa9c339e58..6c96305c43 100644
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    7676        /**
    7777         * @ticket 52991
    7878         * @ticket 54336
     79         * @ticket 56611
    7980         */
    8081        public function test_translations_are_applied() {
    8182                add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) );
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    118119                                                        ),
    119120                                                ),
    120121                                        ),
     122                                        'duotone'        => array(
     123                                                'theme' => array(
     124                                                        array(
     125                                                                'colors' => array( '#333333', '#aaaaaa' ),
     126                                                                'slug'   => 'custom-duotone',
     127                                                                'name'   => 'Custom Duotone',
     128                                                        ),
     129                                                ),
     130                                        ),
    121131                                ),
    122132                                'typography' => array(
    123133                                        'customFontSize' => false,
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    133143                                        ),
    134144                                ),
    135145                                'spacing'    => array(
    136                                         'units'   => array( 'rem' ),
    137                                         'padding' => true,
     146                                        'units'    => array( 'rem' ),
     147                                        'padding'  => true,
     148                                        'blockGap' => true,
    138149                                ),
    139150                                'blocks'     => array(
    140151                                        'core/paragraph' => array(
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    244255
    245256        /**
    246257         * @ticket 54336
     258         * @ticket 56611
    247259         */
    248260        function test_merges_child_theme_json_into_parent_theme_json() {
    249261                switch_theme( 'block-theme-child' );
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    253265                        'color'      => array(
    254266                                'custom'         => false,
    255267                                'customGradient' => false,
     268                                'duotone'        => array(
     269                                        'theme' => array(
     270                                                array(
     271                                                        'colors' => array( '#333333', '#aaaaaa' ),
     272                                                        'name'   => 'Custom Duotone',
     273                                                        'slug'   => 'custom-duotone',
     274                                                ),
     275                                        ),
     276                                ),
    256277                                'gradients'      => array(
    257278                                        'theme' => array(
    258279                                                array(
    class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { 
    297318                                ),
    298319                        ),
    299320                        'spacing'    => array(
    300                                 'units'   => array( 'rem' ),
    301                                 'padding' => true,
     321                                'blockGap' => true,
     322                                'units'    => array( 'rem' ),
     323                                'padding'  => true,
    302324                        ),
    303325                        'blocks'     => array(
    304326                                'core/paragraph'  => array(