Make WordPress Core

Changeset 56701


Ignore:
Timestamp:
09/26/2023 08:07:07 AM (16 months ago)
Author:
gziolo
Message:

Blocks: Add more unit test covering edge cases for Block Hooks

These two new unit tests document how Block Hooks behave with first_child and last_child relative positions. The hooked blocks will only get inserted in the case where the parent block has at least one child block present. While it seems like a limitation, in practice, it's hard to think of a case where the template would use a parent block without its children. It's more likely to happen with patterns in general, but in the case of patterns wired with the block theme, it also seems unlikely. The reasoning here is that out of the box, the block theme should produce a fully functional and valid HTML.

Props ockham.
See #59313.
Follow-up [56649].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/serialize.php

    r56649 r56701  
    236236        $this->assertSame( $original, $actual );
    237237    }
     238
     239    /**
     240     * @ticket 59313
     241     *
     242     * @covers ::traverse_and_serialize_blocks
     243     */
     244    public function test_traverse_and_serialize_blocks_do_not_insert_in_void_block() {
     245        $markup = '<!-- wp:void /-->';
     246        $blocks = parse_blocks( $markup );
     247
     248        $actual = traverse_and_serialize_blocks(
     249            $blocks,
     250            array( __CLASS__, 'insert_next_to_child_blocks_callback' ),
     251            array( __CLASS__, 'insert_next_to_child_blocks_callback' )
     252        );
     253
     254        $this->assertSame( $markup, $actual );
     255    }
     256
     257    /**
     258     * @ticket 59313
     259     *
     260     * @covers ::traverse_and_serialize_blocks
     261     */
     262    public function test_traverse_and_serialize_blocks_do_not_insert_in_empty_parent_block() {
     263        $markup = '<!-- wp:outer --><div class="wp-block-outer"></div><!-- /wp:outer -->';
     264        $blocks = parse_blocks( $markup );
     265
     266        $actual = traverse_and_serialize_blocks(
     267            $blocks,
     268            array( __CLASS__, 'insert_next_to_child_blocks_callback' ),
     269            array( __CLASS__, 'insert_next_to_child_blocks_callback' )
     270        );
     271
     272        $this->assertSame( $markup, $actual );
     273    }
    238274}
Note: See TracChangeset for help on using the changeset viewer.