Skip to content

Commit

Permalink
Add unit test coverage for subsequent insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Sep 26, 2024
1 parent 29fbae6 commit b75c0eb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/phpunit/tests/blocks/insertHookedBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ public function test_insert_hooked_blocks_if_block_has_multiple_false_and_is_alr
$actual,
'Hooked block with "multiple": false should not be inserted if another instance is already present.'
);
$actual = insert_hooked_blocks( $anchor_block, 'before', get_hooked_blocks(), $context );
$this->assertSame(
'',
$actual,
'Hooked block with "multiple": false should not be inserted if another instance is already present.'
);
}

/**
* @ticket 61902
*
* @covers ::insert_hooked_blocks
*/
public function test_insert_hooked_blocks_if_block_has_multiple_false_but_is_not_yet_present() {
$anchor_block = array(
'blockName' => 'tests/anchor-block',
);

$context = new WP_Block_Template();
$context->content = '<!-- wp:' . self::ANCHOR_BLOCK_TYPE . ' /-->';

$expected = '<!-- wp:' . self::OTHER_HOOKED_BLOCK_TYPE . ' /-->';
$actual = insert_hooked_blocks( $anchor_block, 'before', get_hooked_blocks(), $context );
$this->assertSame(
$expected,
$actual,
'Hooked block with "multiple": false should be inserted if another instance is not present.'
);

$context->content = $expected . $context->content; // Simulate result of first insertion.
$actual = insert_hooked_blocks( $anchor_block, 'before', get_hooked_blocks(), $context );
$this->assertSame(
'',
$actual,
'Hooked block with "multiple": false should not be inserted if another instance is already present.'
);
}

/**
Expand Down

0 comments on commit b75c0eb

Please sign in to comment.