Skip to content

Commit

Permalink
Add more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jan 16, 2024
1 parent c1fb76e commit 49aa634
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/phpunit/tests/blocks/insertHookedBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
),
);

Expand All @@ -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( '<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /-->', $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( '<!-- wp:' . self::OTHER_HOOKED_BLOCK_TYPE . ' /-->', $actual );
}
}

0 comments on commit 49aa634

Please sign in to comment.