Make WordPress Core


Ignore:
Timestamp:
01/08/2024 06:12:00 AM (14 months ago)
Author:
isabel_brison
Message:

Editor: add layout classes to legacy Group inner container.

Moves generated layout classes into the Group block inner container in classic themes, so that block gap support can work correctly.

Props flixos90, mukesh27.
Fixes #60130.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/block-supports/layout.php

    r55956 r57246  
    253253        );
    254254    }
     255
     256    /**
     257     * Check that wp_restore_group_inner_container() restores the legacy inner container on the Group block.
     258     *
     259     * @ticket 60130
     260     *
     261     * @covers ::wp_restore_group_inner_container
     262     *
     263     * @dataProvider data_restore_group_inner_container
     264     *
     265     * @param array  $args            Dataset to test.
     266     * @param string $expected_output The expected output.
     267     */
     268    public function test_restore_group_inner_container( $args, $expected_output ) {
     269        $actual_output = wp_restore_group_inner_container( $args['block_content'], $args['block'] );
     270        $this->assertEquals( $expected_output, $actual_output );
     271    }
     272
     273    /**
     274     * Data provider for test_restore_group_inner_container.
     275     *
     276     * @return array
     277     */
     278    public function data_restore_group_inner_container() {
     279        return array(
     280            'group block with existing inner container'    => array(
     281                'args'            => array(
     282                    'block_content' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>',
     283                    'block'         => array(
     284                        'blockName'    => 'core/group',
     285                        'attrs'        => array(
     286                            'layout' => array(
     287                                'type' => 'default',
     288                            ),
     289                        ),
     290                        'innerBlocks'  => array(),
     291                        'innerHTML'    => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>',
     292                        'innerContent' => array(
     293                            '<div class="wp-block-group"><div class="wp-block-group__inner-container">',
     294                            ' ',
     295                            ' </div></div>',
     296                        ),
     297                    ),
     298                ),
     299                'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>',
     300            ),
     301            'group block with no existing inner container' => array(
     302                'args'            => array(
     303                    'block_content' => '<div class="wp-block-group"></div>',
     304                    'block'         => array(
     305                        'blockName'    => 'core/group',
     306                        'attrs'        => array(
     307                            'layout' => array(
     308                                'type' => 'default',
     309                            ),
     310                        ),
     311                        'innerBlocks'  => array(),
     312                        'innerHTML'    => '<div class="wp-block-group"></div>',
     313                        'innerContent' => array(
     314                            '<div class="wp-block-group">',
     315                            ' ',
     316                            ' </div>',
     317                        ),
     318                    ),
     319                ),
     320                'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>',
     321            ),
     322            'group block with layout classnames'           => array(
     323                'args'            => array(
     324                    'block_content' => '<div class="wp-block-group is-layout-constrained wp-block-group-is-layout-constrained"></div>',
     325                    'block'         => array(
     326                        'blockName'    => 'core/group',
     327                        'attrs'        => array(
     328                            'layout' => array(
     329                                'type' => 'default',
     330                            ),
     331                        ),
     332                        'innerBlocks'  => array(),
     333                        'innerHTML'    => '<div class="wp-block-group"></div>',
     334                        'innerContent' => array(
     335                            '<div class="wp-block-group">',
     336                            ' ',
     337                            ' </div>',
     338                        ),
     339                    ),
     340                ),
     341                'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained"></div></div>',
     342            ),
     343        );
     344    }
    255345}
Note: See TracChangeset for help on using the changeset viewer.