Skip to content

Commit 49aa634

Browse files
committed
Add more test coverage
1 parent c1fb76e commit 49aa634

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

tests/phpunit/tests/blocks/insertHookedBlocks.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
2020
'innerContent' => array(),
2121
);
2222

23+
const OTHER_HOOKED_BLOCK_TYPE = 'tests/other-hooked-block';
24+
const OTHER_HOOKED_BLOCK = array(
25+
'blockName' => self::OTHER_HOOKED_BLOCK_TYPE,
26+
'attrs' => array(),
27+
'innerContent' => array(),
28+
);
29+
2330
const HOOKED_BLOCKS = array(
2431
self::ANCHOR_BLOCK_TYPE => array(
25-
'after' => array( self::HOOKED_BLOCK_TYPE ),
32+
'after' => array( self::HOOKED_BLOCK_TYPE ),
33+
'before' => array( self::OTHER_HOOKED_BLOCK_TYPE ),
2634
),
2735
);
2836

@@ -40,4 +48,44 @@ public function test_insert_hooked_blocks_adds_metadata() {
4048
$this->assertSame( array( self::HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] );
4149
$this->assertSame( '<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /-->', $actual );
4250
}
51+
52+
/**
53+
* @ticket 60126
54+
*
55+
* @covers ::insert_hooked_blocks
56+
*/
57+
public function test_insert_hooked_blocks_if_block_is_already_hooked() {
58+
$anchor_block = array(
59+
'blockName' => 'tests/anchor-block',
60+
'attrs' => array(
61+
'metadata' => array(
62+
'ignoredHookedBlocks' => array( self::HOOKED_BLOCK_TYPE ),
63+
),
64+
),
65+
);
66+
67+
$actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
68+
$this->assertSame( array( self::HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] );
69+
$this->assertSame( '', $actual );
70+
}
71+
72+
/**
73+
* @ticket 60126
74+
*
75+
* @covers ::insert_hooked_blocks
76+
*/
77+
public function test_insert_hooked_blocks_adds_to_ignored_hooked_blocks() {
78+
$anchor_block = array(
79+
'blockName' => 'tests/anchor-block',
80+
'attrs' => array(
81+
'metadata' => array(
82+
'ignoredHookedBlocks' => array( self::HOOKED_BLOCK_TYPE ),
83+
),
84+
),
85+
);
86+
87+
$actual = insert_hooked_blocks( $anchor_block, 'before', self::HOOKED_BLOCKS, array() );
88+
$this->assertSame( array( self::HOOKED_BLOCK_TYPE, self::OTHER_HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] );
89+
$this->assertSame( '<!-- wp:' . self::OTHER_HOOKED_BLOCK_TYPE . ' /-->', $actual );
90+
}
4391
}

0 commit comments

Comments
 (0)