Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/phpunit/tests/blocks/applyBlockHooksToContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public static function wpSetUpBeforeClass() {
)
);

register_block_type(
'tests/hooked-block-as-last-child',
array(
'block_hooks' => array(
'tests/anchor-block-for-child-insertion' => 'last_child',
),
)
);

register_block_type(
'tests/hooked-block-with-multiple-false',
array(
Expand Down Expand Up @@ -59,6 +68,7 @@ public static function wpTearDownAfterClass() {
$registry = WP_Block_Type_Registry::get_instance();

$registry->unregister( 'tests/hooked-block' );
$registry->unregister( 'tests/hooked-block-as-last-child' );
$registry->unregister( 'tests/hooked-block-with-multiple-false' );
$registry->unregister( 'tests/dynamically-hooked-block-with-multiple-false' );
}
Expand Down Expand Up @@ -91,6 +101,36 @@ public function test_apply_block_hooks_to_content_inserts_hooked_block() {
);
}

public function test_apply_block_hooks_to_content_inserts_hooked_block_as_last_child_if_sibling_is_present() {
$block_opener = '<!-- wp:tests/anchor-block-for-child-insertion -->';
$block_closer = '<!-- /wp:tests/anchor-block-for-child-insertion -->';
$sibling_block = '<!-- wp:tests/sibling /-->';

$context = new WP_Block_Template();
$context->content = $block_opener . $sibling_block . $block_closer;

$actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' );
$this->assertSame(
$block_opener . $sibling_block . '<!-- wp:tests/hooked-block-as-last-child /-->' . $block_closer,
$actual
);
}

public function test_apply_block_hooks_to_content_inserts_hooked_block_as_last_child_if_sibling_is_classic_block() {
$block_opener = '<!-- wp:tests/anchor-block-for-child-insertion -->';
$block_closer = '<!-- /wp:tests/anchor-block-for-child-insertion -->';
$sibling_block = '<h2>Hello World!</h2>';

$context = new WP_Block_Template();
$context->content = $block_opener . $sibling_block . $block_closer;

$actual = apply_block_hooks_to_content( $context->content, $context, 'insert_hooked_blocks' );
$this->assertSame(
$block_opener . $sibling_block . '<!-- wp:tests/hooked-block-as-last-child /-->' . $block_closer,
$actual
);
}

/**
* @ticket 61074
*/
Expand Down
Loading