From 49aa6345e88f6421fb8daa4e75ffcd8d3a3e73af Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 16 Jan 2024 14:08:27 +0100 Subject: [PATCH] Add more test coverage --- .../tests/blocks/insertHookedBlocks.php | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/insertHookedBlocks.php b/tests/phpunit/tests/blocks/insertHookedBlocks.php index 79d404b1454db..69100d6cc0eb2 100644 --- a/tests/phpunit/tests/blocks/insertHookedBlocks.php +++ b/tests/phpunit/tests/blocks/insertHookedBlocks.php @@ -20,9 +20,17 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase { 'innerContent' => array(), ); + const OTHER_HOOKED_BLOCK_TYPE = 'tests/other-hooked-block'; + const OTHER_HOOKED_BLOCK = array( + 'blockName' => self::OTHER_HOOKED_BLOCK_TYPE, + 'attrs' => array(), + 'innerContent' => array(), + ); + const HOOKED_BLOCKS = array( self::ANCHOR_BLOCK_TYPE => array( - 'after' => array( self::HOOKED_BLOCK_TYPE ), + 'after' => array( self::HOOKED_BLOCK_TYPE ), + 'before' => array( self::OTHER_HOOKED_BLOCK_TYPE ), ), ); @@ -40,4 +48,44 @@ public function test_insert_hooked_blocks_adds_metadata() { $this->assertSame( array( self::HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); $this->assertSame( '', $actual ); } + + /** + * @ticket 60126 + * + * @covers ::insert_hooked_blocks + */ + public function test_insert_hooked_blocks_if_block_is_already_hooked() { + $anchor_block = array( + 'blockName' => 'tests/anchor-block', + 'attrs' => array( + 'metadata' => array( + 'ignoredHookedBlocks' => array( self::HOOKED_BLOCK_TYPE ), + ), + ), + ); + + $actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() ); + $this->assertSame( array( self::HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); + $this->assertSame( '', $actual ); + } + + /** + * @ticket 60126 + * + * @covers ::insert_hooked_blocks + */ + public function test_insert_hooked_blocks_adds_to_ignored_hooked_blocks() { + $anchor_block = array( + 'blockName' => 'tests/anchor-block', + 'attrs' => array( + 'metadata' => array( + 'ignoredHookedBlocks' => array( self::HOOKED_BLOCK_TYPE ), + ), + ), + ); + + $actual = insert_hooked_blocks( $anchor_block, 'before', self::HOOKED_BLOCKS, array() ); + $this->assertSame( array( self::HOOKED_BLOCK_TYPE, self::OTHER_HOOKED_BLOCK_TYPE ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ); + $this->assertSame( '', $actual ); + } }