Make WordPress Core


Ignore:
Timestamp:
09/10/2022 12:37:00 PM (19 months ago)
Author:
SergeyBiryukov
Message:

Editor: Backport Elements API updates.

This commit backports the original PRs from Gutenberg repository:

Props onemaggie, bernhard-reiter, cbravobernal, mmaattiiaass, scruffian, andraganescu, dpcalhoun, get_dave, Mamaduka, SergeyBiryukov.
See #56467.

File:
1 edited

Legend:

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

    r54100 r54118  
    368368
    369369        $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; }.wp-block-group{border-radius: 10px;margin: 1em;padding: 24px;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;padding-top: 15px;}';
    370         $this->assertEquals( $styles, $theme_json->get_stylesheet() );
    371         $this->assertEquals( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
     370        $this->assertSame( $styles, $theme_json->get_stylesheet() );
     371        $this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
    372372    }
    373373
     
    400400
    401401        $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; }';
    402         $this->assertEquals( $expected, $theme_json->get_stylesheet() );
    403         $this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     402        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     403        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
    404404    }
    405405
     
    425425
    426426        $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-block-start: 0; margin-block-end: 0; }.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }';
    427         $this->assertEquals( $expected, $theme_json->get_stylesheet() );
    428         $this->assertEquals( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     427        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     428        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
    429429    }
    430430
     
    458458                            ),
    459459                        ),
    460                     ),
    461                     'spacing'    => array(
    462                         'blockGap' => false,
    463460                    ),
    464461                    'misc'       => 'value',
     
    554551
    555552        $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; }body{color: var(--wp--preset--color--grey);}.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: var( --wp--style--block-gap ); }a{background-color: #333;color: #111;}.wp-block-group{border-radius: 10px;padding: 24px;}.wp-block-group a{color: #111;}h1,h2,h3,h4,h5,h6{color: #123456;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{background-color: #333;color: #111;font-size: 60px;}.wp-block-post-date{color: #123456;}.wp-block-post-date a{background-color: #777;color: #555;}.wp-block-image{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}';
     553        $styles    = 'body { margin: 0; }body{color: var(--wp--preset--color--grey);}.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; }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{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}';
    557554        $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;}';
    558555        $all       = $variables . $styles . $presets;
    559         $this->assertEquals( $all, $theme_json->get_stylesheet() );
    560         $this->assertEquals( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
    561         $this->assertEquals( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
    562         $this->assertEquals( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
     556        $this->assertSame( $all, $theme_json->get_stylesheet() );
     557        $this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
     558        $this->assertSame( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
     559        $this->assertSame( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
    563560    }
    564561
     
    588585        );
    589586
    590         $this->assertEquals(
     587        $this->assertSame(
    591588            'h1.has-white-color,h2.has-white-color,h3.has-white-color,h4.has-white-color,h5.has-white-color,h6.has-white-color{color: var(--wp--preset--color--white) !important;}h1.has-white-background-color,h2.has-white-background-color,h3.has-white-background-color,h4.has-white-background-color,h5.has-white-background-color,h6.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}h1.has-white-border-color,h2.has-white-border-color,h3.has-white-border-color,h4.has-white-border-color,h5.has-white-border-color,h6.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}',
    592589            $theme_json->get_stylesheet( array( 'presets' ) )
     
    632629        $variables = '.wp-block-group{--wp--preset--color--grey: grey;}';
    633630        $all       = $variables . $styles . $presets;
    634         $this->assertEquals( $all, $theme_json->get_stylesheet() );
    635         $this->assertEquals( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
    636         $this->assertEquals( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
    637         $this->assertEquals( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
     631        $this->assertSame( $all, $theme_json->get_stylesheet() );
     632        $this->assertSame( $styles, $theme_json->get_stylesheet( array( 'styles' ) ) );
     633        $this->assertSame( $presets, $theme_json->get_stylesheet( array( 'presets' ) ) );
     634        $this->assertSame( $variables, $theme_json->get_stylesheet( array( 'variables' ) ) );
    638635    }
    639636
     
    673670        );
    674671
    675         $this->assertEquals(
     672        $this->assertSame(
    676673            '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-dark-grey-color{color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-color{color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-color{color: var(--wp--preset--color--white-2-black) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-background-color{background-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-background-color{background-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-background-color{background-color: var(--wp--preset--color--white-2-black) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-dark-grey-border-color{border-color: var(--wp--preset--color--dark-grey) !important;}.has-light-grey-border-color{border-color: var(--wp--preset--color--light-grey) !important;}.has-white-2-black-border-color{border-color: var(--wp--preset--color--white-2-black) !important;}',
    677674            $theme_json->get_stylesheet( array( 'presets' ) )
    678675        );
    679         $this->assertEquals(
     676        $this->assertSame(
    680677            'body{--wp--preset--color--grey: grey;--wp--preset--color--dark-grey: grey;--wp--preset--color--light-grey: grey;--wp--preset--color--white-2-black: grey;--wp--custom--white-2-black: value;}',
    681678            $theme_json->get_stylesheet( array( 'variables' ) )
     
    720717        );
    721718
    722         $this->assertEquals(
     719        $this->assertSame(
    723720            'body{--wp--preset--color--grey: grey;}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; }p{background-color: blue;color: red;font-size: 12px;line-height: 1.3;}.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;}',
    724721            $theme_json->get_stylesheet()
    725722        );
     723    }
     724
     725    /**
     726     * @ticket 56467
     727     */
     728    public function test_get_stylesheet_handles_whitelisted_element_pseudo_selectors() {
     729        $theme_json = new WP_Theme_JSON(
     730            array(
     731                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     732                'styles'  => array(
     733                    'elements' => array(
     734                        'link' => array(
     735                            'color'  => array(
     736                                'text'       => 'green',
     737                                'background' => 'red',
     738                            ),
     739                            ':hover' => array(
     740                                'color'      => array(
     741                                    'text'       => 'red',
     742                                    'background' => 'green',
     743                                ),
     744                                'typography' => array(
     745                                    'textTransform' => 'uppercase',
     746                                    'fontSize'      => '10em',
     747                                ),
     748                            ),
     749                            ':focus' => array(
     750                                'color' => array(
     751                                    'text'       => 'yellow',
     752                                    'background' => 'black',
     753                                ),
     754                            ),
     755                        ),
     756                    ),
     757                ),
     758            )
     759        );
     760
     761        $base_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; }';
     762
     763        $element_styles = 'a:where(:not(.wp-element-button)){background-color: red;color: green;}a:where(:not(.wp-element-button)):hover{background-color: green;color: red;font-size: 10em;text-transform: uppercase;}a:where(:not(.wp-element-button)):focus{background-color: black;color: yellow;}';
     764
     765        $expected = $base_styles . $element_styles;
     766
     767        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     768        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     769    }
     770
     771    /**
     772     * @ticket 56467
     773     */
     774    public function test_get_stylesheet_handles_only_pseudo_selector_rules_for_given_property() {
     775        $theme_json = new WP_Theme_JSON(
     776            array(
     777                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     778                'styles'  => array(
     779                    'elements' => array(
     780                        'link' => array(
     781                            ':hover' => array(
     782                                'color'      => array(
     783                                    'text'       => 'red',
     784                                    'background' => 'green',
     785                                ),
     786                                'typography' => array(
     787                                    'textTransform' => 'uppercase',
     788                                    'fontSize'      => '10em',
     789                                ),
     790                            ),
     791                            ':focus' => array(
     792                                'color' => array(
     793                                    'text'       => 'yellow',
     794                                    'background' => 'black',
     795                                ),
     796                            ),
     797                        ),
     798                    ),
     799                ),
     800            )
     801        );
     802
     803        $base_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; }';
     804
     805        $element_styles = 'a:where(:not(.wp-element-button)):hover{background-color: green;color: red;font-size: 10em;text-transform: uppercase;}a:where(:not(.wp-element-button)):focus{background-color: black;color: yellow;}';
     806
     807        $expected = $base_styles . $element_styles;
     808
     809        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     810        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     811    }
     812
     813    /**
     814     * @ticket 56467
     815     */
     816    public function test_get_stylesheet_ignores_pseudo_selectors_on_non_whitelisted_elements() {
     817        $theme_json = new WP_Theme_JSON(
     818            array(
     819                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     820                'styles'  => array(
     821                    'elements' => array(
     822                        'h4' => array(
     823                            'color'  => array(
     824                                'text'       => 'green',
     825                                'background' => 'red',
     826                            ),
     827                            ':hover' => array(
     828                                'color' => array(
     829                                    'text'       => 'red',
     830                                    'background' => 'green',
     831                                ),
     832                            ),
     833                            ':focus' => array(
     834                                'color' => array(
     835                                    'text'       => 'yellow',
     836                                    'background' => 'black',
     837                                ),
     838                            ),
     839                        ),
     840                    ),
     841                ),
     842            )
     843        );
     844
     845        $base_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; }';
     846
     847        $element_styles = 'h4{background-color: red;color: green;}';
     848
     849        $expected = $base_styles . $element_styles;
     850
     851        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     852        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     853    }
     854
     855    /**
     856     * @ticket 56467
     857     */
     858    public function test_get_stylesheet_ignores_non_whitelisted_pseudo_selectors() {
     859        $theme_json = new WP_Theme_JSON(
     860            array(
     861                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     862                'styles'  => array(
     863                    'elements' => array(
     864                        'link' => array(
     865                            'color'     => array(
     866                                'text'       => 'green',
     867                                'background' => 'red',
     868                            ),
     869                            ':hover'    => array(
     870                                'color' => array(
     871                                    'text'       => 'red',
     872                                    'background' => 'green',
     873                                ),
     874                            ),
     875                            ':levitate' => array(
     876                                'color' => array(
     877                                    'text'       => 'yellow',
     878                                    'background' => 'black',
     879                                ),
     880                            ),
     881                        ),
     882                    ),
     883                ),
     884            )
     885        );
     886
     887        $base_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; }';
     888
     889        $element_styles = 'a:where(:not(.wp-element-button)){background-color: red;color: green;}a:where(:not(.wp-element-button)):hover{background-color: green;color: red;}';
     890
     891        $expected = $base_styles . $element_styles;
     892
     893        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     894        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     895        $this->assertStringNotContainsString( 'a:levitate{', $theme_json->get_stylesheet( array( 'styles' ) ) );
     896    }
     897
     898    /**
     899     * @ticket 56467
     900     */
     901    public function test_get_stylesheet_handles_priority_of_elements_vs_block_elements_pseudo_selectors() {
     902        $theme_json = new WP_Theme_JSON(
     903            array(
     904                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     905                'styles'  => array(
     906                    'blocks' => array(
     907                        'core/group' => array(
     908                            'elements' => array(
     909                                'link' => array(
     910                                    'color'  => array(
     911                                        'text'       => 'green',
     912                                        'background' => 'red',
     913                                    ),
     914                                    ':hover' => array(
     915                                        'color'      => array(
     916                                            'text'       => 'red',
     917                                            'background' => 'green',
     918                                        ),
     919                                        'typography' => array(
     920                                            'textTransform' => 'uppercase',
     921                                            'fontSize' => '10em',
     922                                        ),
     923                                    ),
     924                                    ':focus' => array(
     925                                        'color' => array(
     926                                            'text'       => 'yellow',
     927                                            'background' => 'black',
     928                                        ),
     929                                    ),
     930                                ),
     931                            ),
     932                        ),
     933                    ),
     934                ),
     935            )
     936        );
     937
     938        $base_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; }';
     939
     940        $element_styles = '.wp-block-group a:where(:not(.wp-element-button)){background-color: red;color: green;}.wp-block-group a:where(:not(.wp-element-button)):hover{background-color: green;color: red;font-size: 10em;text-transform: uppercase;}.wp-block-group a:where(:not(.wp-element-button)):focus{background-color: black;color: yellow;}';
     941
     942        $expected = $base_styles . $element_styles;
     943
     944        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     945        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     946    }
     947
     948    /**
     949     * @ticket 56467
     950     */
     951    public function test_get_stylesheet_handles_whitelisted_block_level_element_pseudo_selectors() {
     952        $theme_json = new WP_Theme_JSON(
     953            array(
     954                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     955                'styles'  => array(
     956                    'elements' => array(
     957                        'link' => array(
     958                            'color'  => array(
     959                                'text'       => 'green',
     960                                'background' => 'red',
     961                            ),
     962                            ':hover' => array(
     963                                'color' => array(
     964                                    'text'       => 'red',
     965                                    'background' => 'green',
     966                                ),
     967                            ),
     968                        ),
     969                    ),
     970                    'blocks'   => array(
     971                        'core/group' => array(
     972                            'elements' => array(
     973                                'link' => array(
     974                                    ':hover' => array(
     975                                        'color' => array(
     976                                            'text'       => 'yellow',
     977                                            'background' => 'black',
     978                                        ),
     979                                    ),
     980                                ),
     981                            ),
     982                        ),
     983                    ),
     984                ),
     985            )
     986        );
     987
     988        $base_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; }';
     989
     990        $element_styles = 'a:where(:not(.wp-element-button)){background-color: red;color: green;}a:where(:not(.wp-element-button)):hover{background-color: green;color: red;}.wp-block-group a:where(:not(.wp-element-button)):hover{background-color: black;color: yellow;}';
     991
     992        $expected = $base_styles . $element_styles;
     993
     994        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     995        $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
    726996    }
    727997
     
    20882358
    20892359    /**
     2360     * @ticket 56467
     2361     */
     2362    public function test_remove_invalid_element_pseudo_selectors() {
     2363        $actual = WP_Theme_JSON::remove_insecure_properties(
     2364            array(
     2365                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     2366                'styles'  => array(
     2367                    'elements' => array(
     2368                        'link' => array(
     2369                            'color'  => array(
     2370                                'text'       => 'hotpink',
     2371                                'background' => 'yellow',
     2372                            ),
     2373                            ':hover' => array(
     2374                                'color' => array(
     2375                                    'text'       => 'red',
     2376                                    'background' => 'blue',
     2377                                ),
     2378                            ),
     2379                        ),
     2380                    ),
     2381                ),
     2382            ),
     2383            true
     2384        );
     2385
     2386        $expected = array(
     2387            'version' => WP_Theme_JSON::LATEST_SCHEMA,
     2388            'styles'  => array(
     2389                'elements' => array(
     2390                    'link' => array(
     2391                        'color'  => array(
     2392                            'text'       => 'hotpink',
     2393                            'background' => 'yellow',
     2394                        ),
     2395                        ':hover' => array(
     2396                            'color' => array(
     2397                                'text'       => 'red',
     2398                                'background' => 'blue',
     2399                            ),
     2400                        ),
     2401                    ),
     2402                ),
     2403            ),
     2404        );
     2405
     2406        $this->assertEqualSetsWithIndex( $expected, $actual );
     2407    }
     2408
     2409    /**
    20902410     * @ticket 54336
    20912411     */
     
    26222942        $this->assertEqualSetsWithIndex( $expected, $actual );
    26232943    }
     2944
     2945    /**
     2946     * @ticket 56467
     2947     */
     2948    public function test_get_element_class_name_button() {
     2949        $expected = 'wp-element-button';
     2950        $actual   = WP_Theme_JSON::get_element_class_name( 'button' );
     2951
     2952        $this->assertSame( $expected, $actual );
     2953    }
     2954
     2955    /**
     2956     * @ticket 56467
     2957     */
     2958    public function test_get_element_class_name_invalid() {
     2959        $expected = '';
     2960        $actual   = WP_Theme_JSON::get_element_class_name( 'unknown-element' );
     2961
     2962        $this->assertSame( $expected, $actual );
     2963    }
     2964
     2965    /**
     2966     * Testing that dynamic properties in theme.json return the value they refrence,
     2967     * e.g. array( 'ref' => 'styles.color.background' ) => "#ffffff".
     2968     *
     2969     * @ticket 56467
     2970     */
     2971    public function test_get_property_value_valid() {
     2972        $theme_json = new WP_Theme_JSON(
     2973            array(
     2974                'version' => 2,
     2975                'styles'  => array(
     2976                    'color'    => array(
     2977                        'background' => '#ffffff',
     2978                        'text'       => '#000000',
     2979                    ),
     2980                    'elements' => array(
     2981                        'button' => array(
     2982                            'color' => array(
     2983                                'background' => array( 'ref' => 'styles.color.text' ),
     2984                                'text'       => array( 'ref' => 'styles.color.background' ),
     2985                            ),
     2986                        ),
     2987                    ),
     2988                ),
     2989            )
     2990        );
     2991
     2992        $expected = 'body { margin: 0; }body{background-color: #ffffff;color: #000000;}.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-element-button, .wp-block-button__link{background-color: #000000;color: #ffffff;}';
     2993        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     2994    }
     2995
     2996    /**
     2997     * Testing that dynamic properties in theme.json that refer to other dynamic properties in a loop
     2998     * should be left untouched.
     2999     *
     3000     * @ticket 56467
     3001     * @expectedIncorrectUsage get_property_value
     3002     */
     3003    public function test_get_property_value_loop() {
     3004        $theme_json = new WP_Theme_JSON(
     3005            array(
     3006                'version' => 2,
     3007                'styles'  => array(
     3008                    'color'    => array(
     3009                        'background' => '#ffffff',
     3010                        'text'       => array( 'ref' => 'styles.elements.button.color.background' ),
     3011                    ),
     3012                    'elements' => array(
     3013                        'button' => array(
     3014                            'color' => array(
     3015                                'background' => array( 'ref' => 'styles.color.text' ),
     3016                                'text'       => array( 'ref' => 'styles.color.background' ),
     3017                            ),
     3018                        ),
     3019                    ),
     3020                ),
     3021            )
     3022        );
     3023
     3024        $expected = 'body { margin: 0; }body{background-color: #ffffff;}.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-element-button, .wp-block-button__link{color: #ffffff;}';
     3025        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     3026    }
     3027
     3028    /**
     3029     * Testing that dynamic properties in theme.json that refer to other dynamic properties
     3030     * should be left unprocessed.
     3031     *
     3032     * @ticket 56467
     3033     * @expectedIncorrectUsage get_property_value
     3034     */
     3035    public function test_get_property_value_recursion() {
     3036        $theme_json = new WP_Theme_JSON(
     3037            array(
     3038                'version' => 2,
     3039                'styles'  => array(
     3040                    'color'    => array(
     3041                        'background' => '#ffffff',
     3042                        'text'       => array( 'ref' => 'styles.color.background' ),
     3043                    ),
     3044                    'elements' => array(
     3045                        'button' => array(
     3046                            'color' => array(
     3047                                'background' => array( 'ref' => 'styles.color.text' ),
     3048                                'text'       => array( 'ref' => 'styles.color.background' ),
     3049                            ),
     3050                        ),
     3051                    ),
     3052                ),
     3053            )
     3054        );
     3055
     3056        $expected = 'body { margin: 0; }body{background-color: #ffffff;color: #ffffff;}.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-element-button, .wp-block-button__link{color: #ffffff;}';
     3057        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     3058    }
     3059
     3060    /**
     3061     * Testing that dynamic properties in theme.json that refer to themselves
     3062     * should be left unprocessed.
     3063     *
     3064     * @ticket 56467
     3065     * @expectedIncorrectUsage get_property_value
     3066     */
     3067    public function test_get_property_value_self() {
     3068        $theme_json = new WP_Theme_JSON(
     3069            array(
     3070                'version' => 2,
     3071                'styles'  => array(
     3072                    'color' => array(
     3073                        'background' => '#ffffff',
     3074                        'text'       => array( 'ref' => 'styles.color.text' ),
     3075                    ),
     3076                ),
     3077            )
     3078        );
     3079
     3080        $expected = 'body { margin: 0; }body{background-color: #ffffff;}.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; }';
     3081        $this->assertSame( $expected, $theme_json->get_stylesheet() );
     3082    }
     3083
    26243084}
Note: See TracChangeset for help on using the changeset viewer.