Make WordPress Core


Ignore:
Timestamp:
09/14/2022 06:42:04 PM (4 years ago)
Author:
hellofromTonya
Message:

Editor: Backport foundation for Layout block support refactor (part 1).

Backports the following changes from the Gutenberg repository:

  • [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json
  • [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544
  • [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087
  • [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792
  • [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544
  • [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665
  • [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085

Notes:

  • It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting layout.php.
  • [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of trunk. There were various outages today of upstream wp-env dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current trunk. See PR 3205 for more details.
  • Giving additional props for those who did a deep dive investigation into the failed tests.

Follow-up to [54160], [54159].

Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya.
See #56467.

File:
1 edited

Legend:

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

    r54160 r54162  
    424424                );
    425425
    426                 $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 ); }';
     426                $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: 1em; }body { --wp--style--block-gap: 1em; }';
    427427                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    428428                $this->assertSame( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
     
    545545                                                ),
    546546                                        ),
     547                                        'spacing'  => array(
     548                                                'blockGap' => '24px',
     549                                        ),
    547550                                ),
    548551                                'misc'     => 'value',
     
    551554
    552555                $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;}';
    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;}';
     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{border-top-left-radius: 10px;border-bottom-right-radius: 1em;margin-bottom: 30px;}';
    554557                $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;}';
    555558                $all       = $variables . $styles . $presets;
     
    26762679                                                'core/group' => array(
    26772680                                                        'spacing' => array(
    2678                                                                 'margin'   => 'valid value',
    2679                                                                 'blockGap' => 'invalid value',
     2681                                                                'margin'  => 'valid value',
     2682                                                                'display' => 'none',
    26802683                                                        ),
    26812684                                                ),
     
    29902993                );
    29912994
    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;}';
     2995                $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; }body{background-color: #ffffff;color: #000000;}.wp-element-button, .wp-block-button__link{background-color: #000000;color: #ffffff;}';
    29932996                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    29942997        }
     
    30223025                );
    30233026
    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;}';
     3027                $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; }body{background-color: #ffffff;}.wp-element-button, .wp-block-button__link{color: #ffffff;}';
    30253028                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    30263029        }
     
    30543057                );
    30553058
    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;}';
     3059                $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; }body{background-color: #ffffff;color: #ffffff;}.wp-element-button, .wp-block-button__link{color: #ffffff;}';
    30573060                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    30583061        }
     
    30783081                );
    30793082
    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; }';
     3083                $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; }body{background-color: #ffffff;}';
    30813084                $this->assertSame( $expected, $theme_json->get_stylesheet() );
    30823085        }
    30833086
     3087
     3088        /**
     3089         * @dataProvider data_get_layout_definitions
     3090         *
     3091         * @ticket 56467
     3092         *
     3093         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3094         */
     3095        public function test_get_stylesheet_generates_layout_styles( $layout_definitions ) {
     3096                $theme_json = new WP_Theme_JSON(
     3097                        array(
     3098                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3099                                'settings' => array(
     3100                                        'layout'  => array(
     3101                                                'definitions' => $layout_definitions,
     3102                                        ),
     3103                                        'spacing' => array(
     3104                                                'blockGap' => true,
     3105                                        ),
     3106                                ),
     3107                                'styles'   => array(
     3108                                        'spacing' => array(
     3109                                                'blockGap' => '1em',
     3110                                        ),
     3111                                ),
     3112                        ),
     3113                        'default'
     3114                );
     3115
     3116                // Results also include root site blocks styles.
     3117                $this->assertSame(
     3118                        '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: 1em; }body { --wp--style--block-gap: 1em; }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: 1em;margin-block-end: 0;}body .is-layout-flex{gap: 1em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
     3119                        $theme_json->get_stylesheet( array( 'styles' ) )
     3120                );
     3121        }
     3122
     3123        /**
     3124         * @dataProvider data_get_layout_definitions
     3125         *
     3126         * @ticket 56467
     3127         *
     3128         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3129         */
     3130        public function test_get_stylesheet_generates_layout_styles_with_spacing_presets( $layout_definitions ) {
     3131                $theme_json = new WP_Theme_JSON(
     3132                        array(
     3133                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3134                                'settings' => array(
     3135                                        'layout'  => array(
     3136                                                'definitions' => $layout_definitions,
     3137                                        ),
     3138                                        'spacing' => array(
     3139                                                'blockGap' => true,
     3140                                        ),
     3141                                ),
     3142                                'styles'   => array(
     3143                                        'spacing' => array(
     3144                                                'blockGap' => 'var:preset|spacing|60',
     3145                                        ),
     3146                                ),
     3147                        ),
     3148                        'default'
     3149                );
     3150
     3151                // Results also include root site blocks styles.
     3152                $this->assertSame(
     3153                        '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: var(--wp--preset--spacing--60); }body { --wp--style--block-gap: var(--wp--preset--spacing--60); }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: var(--wp--preset--spacing--60);margin-block-end: 0;}body .is-layout-flex{gap: var(--wp--preset--spacing--60);}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
     3154                        $theme_json->get_stylesheet( array( 'styles' ) )
     3155                );
     3156        }
     3157
     3158        /**
     3159         * @dataProvider data_get_layout_definitions
     3160         *
     3161         * @ticket 56467
     3162         *
     3163         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3164         */
     3165        public function test_get_stylesheet_generates_fallback_gap_layout_styles( $layout_definitions ) {
     3166                $theme_json = new WP_Theme_JSON(
     3167                        array(
     3168                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3169                                'settings' => array(
     3170                                        'layout'  => array(
     3171                                                'definitions' => $layout_definitions,
     3172                                        ),
     3173                                        'spacing' => array(
     3174                                                'blockGap' => null,
     3175                                        ),
     3176                                ),
     3177                                'styles'   => array(
     3178                                        'spacing' => array(
     3179                                                'blockGap' => '1em',
     3180                                        ),
     3181                                ),
     3182                        ),
     3183                        'default'
     3184                );
     3185                $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) );
     3186
     3187                // Results also include root site blocks styles.
     3188                $this->assertSame(
     3189                        '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; }:where(.is-layout-flex){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}',
     3190                        $stylesheet
     3191                );
     3192        }
     3193
     3194        /**
     3195         * @dataProvider data_get_layout_definitions
     3196         *
     3197         * @ticket 56467
     3198         *
     3199         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3200         */
     3201        public function test_get_stylesheet_generates_base_fallback_gap_layout_styles( $layout_definitions ) {
     3202                $theme_json = new WP_Theme_JSON(
     3203                        array(
     3204                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3205                                'settings' => array(
     3206                                        'layout'  => array(
     3207                                                'definitions' => $layout_definitions,
     3208                                        ),
     3209                                        'spacing' => array(
     3210                                                'blockGap' => null,
     3211                                        ),
     3212                                ),
     3213                        ),
     3214                        'default'
     3215                );
     3216                $stylesheet = $theme_json->get_stylesheet( array( 'base-layout-styles' ) );
     3217
     3218                // Note the `base-layout-styles` includes a fallback gap for the Columns block for backwards compatibility.
     3219                $this->assertSame(
     3220                        ':where(.is-layout-flex){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}:where(.wp-block-columns.is-layout-flex){gap: 2em;}',
     3221                        $stylesheet
     3222                );
     3223        }
     3224
     3225        /**
     3226         * @dataProvider data_get_layout_definitions
     3227         *
     3228         * @ticket 56467
     3229         *
     3230         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3231         */
     3232        public function test_get_stylesheet_skips_layout_styles( $layout_definitions ) {
     3233                add_theme_support( 'disable-layout-styles' );
     3234                $theme_json = new WP_Theme_JSON(
     3235                        array(
     3236                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3237                                'settings' => array(
     3238                                        'layout'  => array(
     3239                                                'definitions' => $layout_definitions,
     3240                                        ),
     3241                                        'spacing' => array(
     3242                                                'blockGap' => null,
     3243                                        ),
     3244                                ),
     3245                        ),
     3246                        'default'
     3247                );
     3248                $stylesheet = $theme_json->get_stylesheet( array( 'base-layout-styles' ) );
     3249                remove_theme_support( 'disable-layout-styles' );
     3250
     3251                // All Layout styles should be skipped.
     3252                $this->assertSame(
     3253                        '',
     3254                        $stylesheet
     3255                );
     3256        }
     3257
     3258        /**
     3259         * @dataProvider data_get_layout_definitions
     3260         *
     3261         * @ticket 56467
     3262         *
     3263         * @param array $layout_definitions Layout definitions as stored in core theme.json.
     3264         */
     3265        public function test_get_stylesheet_generates_valid_block_gap_values_and_skips_null_or_false_values( $layout_definitions ) {
     3266                $theme_json = new WP_Theme_JSON(
     3267                        array(
     3268                                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     3269                                'settings' => array(
     3270                                        'layout'  => array(
     3271                                                'definitions' => $layout_definitions,
     3272                                        ),
     3273                                        'spacing' => array(
     3274                                                'blockGap' => true,
     3275                                        ),
     3276                                ),
     3277                                'styles'   => array(
     3278                                        'spacing' => array(
     3279                                                'blockGap' => '1rem',
     3280                                        ),
     3281                                        'blocks'  => array(
     3282                                                'core/post-content' => array(
     3283                                                        'color' => array(
     3284                                                                'text' => 'gray', // This value should not render block layout styles.
     3285                                                        ),
     3286                                                ),
     3287                                                'core/social-links' => array(
     3288                                                        'spacing' => array(
     3289                                                                'blockGap' => '0', // This value should render block layout gap as zero.
     3290                                                        ),
     3291                                                ),
     3292                                                'core/buttons'      => array(
     3293                                                        'spacing' => array(
     3294                                                                'blockGap' => 0, // This value should render block layout gap as zero.
     3295                                                        ),
     3296                                                ),
     3297                                                'core/columns'      => array(
     3298                                                        'spacing' => array(
     3299                                                                'blockGap' => false, // This value should be ignored. The block will use the global layout value.
     3300                                                        ),
     3301                                                ),
     3302                                        ),
     3303                                ),
     3304                        ),
     3305                        'default'
     3306                );
     3307
     3308                $this->assertEquals(
     3309                        '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: 1rem; }body { --wp--style--block-gap: 1rem; }body .is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}body .is-layout-flow > * + *{margin-block-start: 1rem;margin-block-end: 0;}body .is-layout-flex{gap: 1rem;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}.wp-block-post-content{color: gray;}.wp-block-social-links.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-social-links.is-layout-flex{gap: 0;}.wp-block-buttons.is-layout-flow > *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flow > * + *{margin-block-start: 0;margin-block-end: 0;}.wp-block-buttons.is-layout-flex{gap: 0;}',
     3310                        $theme_json->get_stylesheet()
     3311                );
     3312        }
     3313
     3314        /**
     3315         * Data provider for layout tests.
     3316         *
     3317         * @ticket 56467
     3318         *
     3319         * @return array
     3320         */
     3321        public function data_get_layout_definitions() {
     3322                return array(
     3323                        'layout definitions' => array(
     3324                                array(
     3325                                        'default' => array(
     3326                                                'name'          => 'default',
     3327                                                'slug'          => 'flow',
     3328                                                'className'     => 'is-layout-flow',
     3329                                                'baseStyles'    => array(
     3330                                                        array(
     3331                                                                'selector' => ' > .alignleft',
     3332                                                                'rules'    => array(
     3333                                                                        'float'               => 'left',
     3334                                                                        'margin-inline-start' => '0',
     3335                                                                        'margin-inline-end'   => '2em',
     3336                                                                ),
     3337                                                        ),
     3338                                                        array(
     3339                                                                'selector' => ' > .alignright',
     3340                                                                'rules'    => array(
     3341                                                                        'float'               => 'right',
     3342                                                                        'margin-inline-start' => '2em',
     3343                                                                        'margin-inline-end'   => '0',
     3344                                                                ),
     3345                                                        ),
     3346                                                        array(
     3347                                                                'selector' => ' > .aligncenter',
     3348                                                                'rules'    => array(
     3349                                                                        'margin-left'  => 'auto !important',
     3350                                                                        'margin-right' => 'auto !important',
     3351                                                                ),
     3352                                                        ),
     3353                                                ),
     3354                                                'spacingStyles' => array(
     3355                                                        array(
     3356                                                                'selector' => ' > *',
     3357                                                                'rules'    => array(
     3358                                                                        'margin-block-start' => '0',
     3359                                                                        'margin-block-end'   => '0',
     3360                                                                ),
     3361                                                        ),
     3362                                                        array(
     3363                                                                'selector' => ' > * + *',
     3364                                                                'rules'    => array(
     3365                                                                        'margin-block-start' => null,
     3366                                                                        'margin-block-end'   => '0',
     3367                                                                ),
     3368                                                        ),
     3369                                                ),
     3370                                        ),
     3371                                        'flex'    => array(
     3372                                                'name'          => 'flex',
     3373                                                'slug'          => 'flex',
     3374                                                'className'     => 'is-layout-flex',
     3375                                                'displayMode'   => 'flex',
     3376                                                'baseStyles'    => array(
     3377                                                        array(
     3378                                                                'selector' => '',
     3379                                                                'rules'    => array(
     3380                                                                        'flex-wrap'   => 'wrap',
     3381                                                                        'align-items' => 'center',
     3382                                                                ),
     3383                                                        ),
     3384                                                ),
     3385                                                'spacingStyles' => array(
     3386                                                        array(
     3387                                                                'selector' => '',
     3388                                                                'rules'    => array(
     3389                                                                        'gap' => null,
     3390                                                                ),
     3391                                                        ),
     3392                                                ),
     3393                                        ),
     3394                                ),
     3395                        ),
     3396                );
     3397        }
     3398
     3399        /**
     3400         * @ticket 56467
     3401         */
     3402        function test_get_styles_for_block_with_padding_aware_alignments() {
     3403                $theme_json = new WP_Theme_JSON(
     3404                        array(
     3405                                'version'  => 2,
     3406                                'styles'   => array(
     3407                                        'spacing' => array(
     3408                                                'padding' => array(
     3409                                                        'top'    => '10px',
     3410                                                        'right'  => '12px',
     3411                                                        'bottom' => '10px',
     3412                                                        'left'   => '12px',
     3413                                                ),
     3414                                        ),
     3415                                ),
     3416                                'settings' => array(
     3417                                        'useRootPaddingAwareAlignments' => true,
     3418                                ),
     3419                        )
     3420                );
     3421
     3422                $metadata = array(
     3423                        'path'     => array(
     3424                                '0' => 'styles',
     3425                        ),
     3426                        'selector' => 'body',
     3427                );
     3428
     3429                $expected    = 'body { margin: 0; }.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }.has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 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{--wp--style--root--padding-top: 10px;--wp--style--root--padding-right: 12px;--wp--style--root--padding-bottom: 10px;--wp--style--root--padding-left: 12px;}';
     3430                $root_rules  = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
     3431                $style_rules = $theme_json->get_styles_for_block( $metadata );
     3432                $this->assertSame( $expected, $root_rules . $style_rules );
     3433        }
     3434
     3435        /**
     3436         * @ticket 56467
     3437         */
     3438        function test_get_styles_for_block_without_padding_aware_alignments() {
     3439                $theme_json = new WP_Theme_JSON(
     3440                        array(
     3441                                'version' => 2,
     3442                                'styles'  => array(
     3443                                        'spacing' => array(
     3444                                                'padding' => array(
     3445                                                        'top'    => '10px',
     3446                                                        'right'  => '12px',
     3447                                                        'bottom' => '10px',
     3448                                                        'left'   => '12px',
     3449                                                ),
     3450                                        ),
     3451                                ),
     3452                        )
     3453                );
     3454
     3455                $metadata = array(
     3456                        'path'     => array(
     3457                                '0' => 'styles',
     3458                        ),
     3459                        'selector' => 'body',
     3460                );
     3461
     3462                $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; }body{padding-top: 10px;padding-right: 12px;padding-bottom: 10px;padding-left: 12px;}';
     3463                $root_rules  = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
     3464                $style_rules = $theme_json->get_styles_for_block( $metadata );
     3465                $this->assertSame( $expected, $root_rules . $style_rules );
     3466        }
     3467
     3468        /**
     3469         * @ticket 56467
     3470         */
     3471        function test_get_styles_for_block_with_content_width() {
     3472                $theme_json = new WP_Theme_JSON(
     3473                        array(
     3474                                'version'  => 2,
     3475                                'settings' => array(
     3476                                        'layout' => array(
     3477                                                'contentSize' => '800px',
     3478                                                'wideSize'    => '1000px',
     3479                                        ),
     3480                                ),
     3481                        )
     3482                );
     3483
     3484                $metadata = array(
     3485                        'path'     => array(
     3486                                '0' => 'settings',
     3487                        ),
     3488                        'selector' => 'body',
     3489                );
     3490
     3491                $expected    = 'body { margin: 0;--wp--style--global--content-size: 800px;--wp--style--global--wide-size: 1000px; }.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; }';
     3492                $root_rules  = $theme_json->get_root_layout_rules( WP_Theme_JSON::ROOT_BLOCK_SELECTOR, $metadata );
     3493                $style_rules = $theme_json->get_styles_for_block( $metadata );
     3494                $this->assertSame( $expected, $root_rules . $style_rules );
     3495        }
    30843496}
Note: See TracChangeset for help on using the changeset viewer.