Make WordPress Core


Ignore:
Timestamp:
05/03/2024 04:45:20 AM (12 months ago)
Author:
isabel_brison
Message:

Editor: add Style Engine support for nested CSS rules.

Adds support for passing a $rules_group string to wp_style_engine_get_stylesheet_from_css_rules(), so rules can be nested under a media query, layer or other rule.

Props isabel_brison, ramonopoly.
Fixes #61099.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/style-engine/styleEngine.php

    r57491 r58089  
    750750        $this->assertSame( '.gandalf{color:white;height:190px;border-style:dotted;padding:10px;margin-bottom:100px;}.dumbledore{color:grey;height:90px;border-style:dotted;}.rincewind{color:grey;height:90px;border-style:dotted;}', $compiled_stylesheet );
    751751    }
     752
     753    /**
     754     * Tests returning a generated stylesheet from a set of nested rules and merging their declarations.
     755     *
     756     * @ticket 61099
     757     *
     758     * @covers ::wp_style_engine_get_stylesheet_from_css_rules
     759     */
     760    public function test_should_merge_declarations_for_rules_groups() {
     761        $css_rules = array(
     762            array(
     763                'selector'     => '.saruman',
     764                'rules_group'  => '@container (min-width: 700px)',
     765                'declarations' => array(
     766                    'color'        => 'white',
     767                    'height'       => '100px',
     768                    'border-style' => 'solid',
     769                    'align-self'   => 'stretch',
     770                ),
     771            ),
     772            array(
     773                'selector'     => '.saruman',
     774                'rules_group'  => '@container (min-width: 700px)',
     775                'declarations' => array(
     776                    'color'       => 'black',
     777                    'font-family' => 'The-Great-Eye',
     778                ),
     779            ),
     780        );
     781
     782        $compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules, array( 'prettify' => false ) );
     783
     784        $this->assertSame( '@container (min-width: 700px){.saruman{color:black;height:100px;border-style:solid;align-self:stretch;font-family:The-Great-Eye;}}', $compiled_stylesheet );
     785    }
     786
     787    /**
     788     * Tests returning a generated stylesheet from a set of nested rules.
     789     *
     790     * @ticket 61099
     791     *
     792     * @covers ::wp_style_engine_get_stylesheet_from_css_rules
     793     */
     794    public function test_should_return_stylesheet_with_nested_rules() {
     795        $css_rules = array(
     796            array(
     797                'rules_group'  => '.foo',
     798                'selector'     => '@media (orientation: landscape)',
     799                'declarations' => array(
     800                    'background-color' => 'blue',
     801                ),
     802            ),
     803            array(
     804                'rules_group'  => '.foo',
     805                'selector'     => '@media (min-width > 1024px)',
     806                'declarations' => array(
     807                    'background-color' => 'cotton-blue',
     808                ),
     809            ),
     810        );
     811
     812        $compiled_stylesheet = wp_style_engine_get_stylesheet_from_css_rules( $css_rules, array( 'prettify' => false ) );
     813
     814        $this->assertSame( '.foo{@media (orientation: landscape){background-color:blue;}}.foo{@media (min-width > 1024px){background-color:cotton-blue;}}', $compiled_stylesheet );
     815    }
    752816}
Note: See TracChangeset for help on using the changeset viewer.