Make WordPress Core


Ignore:
Timestamp:
05/28/2024 06:04:37 AM (2 years ago)
Author:
noisysocks
Message:

Block Themes: Allow setting site-wide background images in theme.json

Syncs the necessary changes from Gutenberg to allow setting site-wide
background images using the top-level styles.background key in theme.json.

Props ramonopoly.
Fixes #61123.

File:
1 edited

Legend:

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

    r58173 r58222  
    49864986
    49874987        /**
     4988         * Tests that theme background image styles are correctly generated.
     4989         *
     4990         * @ticket 61123
     4991         */
     4992        public function test_get_top_level_background_image_styles() {
     4993                $theme_json = new WP_Theme_JSON(
     4994                        array(
     4995                                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     4996                                'styles'  => array(
     4997                                        'background' => array(
     4998                                                'backgroundImage'    => array(
     4999                                                        'url' => 'http://example.org/image.png',
     5000                                                ),
     5001                                                'backgroundSize'     => 'contain',
     5002                                                'backgroundRepeat'   => 'no-repeat',
     5003                                                'backgroundPosition' => 'center center',
     5004                                        ),
     5005                                        'blocks'     => array(
     5006                                                'core/paragraph' => array(
     5007                                                        'background' => array(
     5008                                                                'backgroundImage'    => array(
     5009                                                                        'url' => 'http://example.org/image.png',
     5010                                                                ),
     5011                                                                'backgroundSize'     => 'cover',
     5012                                                                'backgroundRepeat'   => 'no-repeat',
     5013                                                                'backgroundPosition' => 'center center',
     5014                                                        ),
     5015                                                ),
     5016                                        ),
     5017                                        'elements'   => array(
     5018                                                'button' => array(
     5019                                                        'background' => array(
     5020                                                                'backgroundImage'    => array(
     5021                                                                        'url' => 'http://example.org/image.png',
     5022                                                                ),
     5023                                                                'backgroundSize'     => 'cover',
     5024                                                                'backgroundRepeat'   => 'no-repeat',
     5025                                                                'backgroundPosition' => 'center center',
     5026                                                        ),
     5027                                                ),
     5028                                        ),
     5029                                ),
     5030                        )
     5031                );
     5032
     5033                $expected_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; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){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-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
     5034                $this->assertSame( $expected_styles, $theme_json->get_stylesheet(), 'Styles returned from "::get_stylesheet()" with top-level background styles type does not match expectations' );
     5035
     5036                $theme_json = new WP_Theme_JSON(
     5037                        array(
     5038                                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     5039                                'styles'  => array(
     5040                                        'background' => array(
     5041                                                'backgroundImage'    => "url('http://example.org/image.png')",
     5042                                                'backgroundSize'     => 'contain',
     5043                                                'backgroundRepeat'   => 'no-repeat',
     5044                                                'backgroundPosition' => 'center center',
     5045                                        ),
     5046                                ),
     5047                        )
     5048                );
     5049
     5050                $expected_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; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){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-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}body{background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
     5051                $this->assertSame( $expected_styles, $theme_json->get_stylesheet(), 'Styles returned from "::get_stylesheet()" with top-level background image as string type does not match expectations' );
     5052        }
     5053
     5054        /**
    49885055         * @ticket 57536
    49895056         */
Note: See TracChangeset for help on using the changeset viewer.