Make WordPress Core


Ignore:
Timestamp:
07/24/2024 12:24:31 AM (16 months ago)
Author:
noisysocks
Message:

Block themes: Enable block-level background image styles

Allows defining background images for blocks in theme.json.

Syncs PHP changes from https://github.com/WordPress/gutenberg/pull/60100.

Props ramonopoly, aaronrobertshaw.
Fixes #61588.

File:
1 edited

Legend:

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

    r58749 r58797  
    50225022
    50235023        $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
    5024         $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type does not match expectations' );
     5024        $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background styles type do not match expectations' );
    50255025
    50265026        $theme_json = new WP_Theme_JSON(
     
    50395039
    50405040        $expected_styles = "html{min-height: calc(100% - var(--wp-admin--admin-bar--height, 0px));}:root :where(body){background-image: url('http://example.org/image.png');background-position: center center;background-repeat: no-repeat;background-size: contain;}";
    5041         $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background image as string type does not match expectations' );
     5041        $this->assertSame( $expected_styles, $theme_json->get_styles_for_block( $body_node ), 'Styles returned from "::get_stylesheet()" with top-level background image as string type do not match expectations' );
     5042    }
     5043
     5044    /**
     5045     * @ticket 61588
     5046     */
     5047    public function test_get_block_background_image_styles() {
     5048        $theme_json = new WP_Theme_JSON(
     5049            array(
     5050                'version' => WP_Theme_JSON::LATEST_SCHEMA,
     5051                'styles'  => array(
     5052                    'blocks' => array(
     5053                        'core/group' => array(
     5054                            'background' => array(
     5055                                'backgroundImage'    => "url('http://example.org/group.png')",
     5056                                'backgroundSize'     => 'cover',
     5057                                'backgroundRepeat'   => 'no-repeat',
     5058                                'backgroundPosition' => 'center center',
     5059                            ),
     5060                        ),
     5061                        'core/quote' => array(
     5062                            'background' => array(
     5063                                'backgroundImage'    => array(
     5064                                    'url' => 'http://example.org/quote.png',
     5065                                ),
     5066                                'backgroundSize'     => 'cover',
     5067                                'backgroundRepeat'   => 'no-repeat',
     5068                                'backgroundPosition' => 'center center',
     5069                            ),
     5070                        ),
     5071                    ),
     5072                ),
     5073            )
     5074        );
     5075
     5076        $quote_node = array(
     5077            'name'      => 'core/quote',
     5078            'path'      => array( 'styles', 'blocks', 'core/quote' ),
     5079            'selector'  => '.wp-block-quote',
     5080            'selectors' => array(
     5081                'root' => '.wp-block-quote',
     5082            ),
     5083        );
     5084
     5085        $quote_styles = ":root :where(.wp-block-quote){background-image: url('http://example.org/quote.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}";
     5086        $this->assertSame( $quote_styles, $theme_json->get_styles_for_block( $quote_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles do not match expectations' );
     5087
     5088        $group_node = array(
     5089            'name'      => 'core/group',
     5090            'path'      => array( 'styles', 'blocks', 'core/group' ),
     5091            'selector'  => '.wp-block-group',
     5092            'selectors' => array(
     5093                'root' => '.wp-block-group',
     5094            ),
     5095        );
     5096
     5097        $group_styles = ":root :where(.wp-block-group){background-image: url('http://example.org/group.png');background-position: center center;background-repeat: no-repeat;background-size: cover;}";
     5098        $this->assertSame( $group_styles, $theme_json->get_styles_for_block( $group_node ), 'Styles returned from "::get_styles_for_block()" with block-level background styles as string type do not match expectations' );
    50425099    }
    50435100
Note: See TracChangeset for help on using the changeset viewer.