Make WordPress Core


Ignore:
Timestamp:
06/12/2024 07:15:06 AM (21 months ago)
Author:
oandregal
Message:

Editor: register block style variations defined by the theme using the init action.

Props oandregal, aaronrobertshaw, annezazu.

Follow-up to [58264].
See #61312.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php

    r58328 r58394  
    604604
    605605    /**
     606     * Tests the submission of a custom block style variation that was defined
     607     * within a theme style variation and wouldn't be registered at the time
     608     * of saving via the API.
     609     *
     610     * @covers WP_REST_Global_Styles_Controller_Gutenberg::update_item
     611     * @ticket 61312
     612     */
     613    public function test_update_item_with_custom_block_style_variations() {
     614        wp_set_current_user( self::$admin_id );
     615        if ( is_multisite() ) {
     616            grant_super_admin( self::$admin_id );
     617        }
     618
     619        $group_variations = array(
     620            'fromThemeStyleVariation' => array(
     621                'color' => array(
     622                    'background' => '#ffffff',
     623                    'text'       => '#000000',
     624                ),
     625            ),
     626        );
     627
     628        $request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' . self::$global_styles_id );
     629        $request->set_body_params(
     630            array(
     631                'styles' => array(
     632                    'blocks' => array(
     633                        'variations' => array(
     634                            'fromThemeStyleVariation' => array(
     635                                'blockTypes' => array( 'core/group', 'core/columns' ),
     636                                'color'      => array(
     637                                    'background' => '#000000',
     638                                    'text'       => '#ffffff',
     639                                ),
     640                            ),
     641                        ),
     642                        'core/group' => array(
     643                            'variations' => $group_variations,
     644                        ),
     645                    ),
     646                ),
     647            )
     648        );
     649        $response = rest_get_server()->dispatch( $request );
     650        $data     = $response->get_data();
     651        $this->assertSame( $group_variations, $data['styles']['blocks']['core/group']['variations'] );
     652    }
     653
     654    /**
    606655     * @doesNotPerformAssertions
    607656     */
Note: See TracChangeset for help on using the changeset viewer.