Skip to content

Commit d47515c

Browse files
committed
Tests: Add additional tests covering Block Hooks registration
Props ockham. See #59346. Follow-up [56587]. git-svn-id: https://develop.svn.wordpress.org/trunk@56607 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3239a8e commit d47515c

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "tests/hooked-block-error",
3+
"description": "A block that throws an error because it tries to hook a block to itself.",
4+
"blockHooks": {
5+
"tests/hooked-block-error": "before",
6+
"tests/other-block": "after"
7+
}
8+
}

‎tests/phpunit/data/blocks/notice/block.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
"root": ".wp-block-notice"
3232
},
3333
"blockHooks": {
34-
"core/post-content": "before"
34+
"tests/before": "before",
35+
"tests/after": "after",
36+
"tests/first-child": "firstChild",
37+
"tests/last-child": "lastChild"
3538
},
3639
"supports": {
3740
"align": true,

‎tests/phpunit/tests/blocks/register.php‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,13 @@ public function test_block_registers_with_metadata_fixture() {
645645
'Block type should contain selectors from metadata.'
646646
);
647647
// @ticket 59346
648-
$this->assertSame(
649-
array( 'core/post-content' => 'before' ),
648+
$this->assertSameSets(
649+
array(
650+
'tests/before' => 'before',
651+
'tests/after' => 'after',
652+
'tests/first-child' => 'first_child',
653+
'tests/last-child' => 'last_child',
654+
),
650655
$result->block_hooks,
651656
'Block type should contain block hooks from metadata.'
652657
);
@@ -1069,4 +1074,22 @@ public function test_register_block_style_name_without_spaces() {
10691074
$actual = register_block_style( 'core/query', $block_styles );
10701075
$this->assertTrue( $actual );
10711076
}
1077+
1078+
/**
1079+
* @ticket 59346
1080+
*
1081+
* @covers ::register_block_type
1082+
*
1083+
* @expectedIncorrectUsage register_block_type_from_metadata
1084+
*/
1085+
public function test_register_block_hooks_targeting_itself() {
1086+
$block_type = register_block_type(
1087+
DIR_TESTDATA . '/blocks/hooked-block-error'
1088+
);
1089+
1090+
$this->assertSame(
1091+
array( 'tests/other-block' => 'after' ),
1092+
$block_type->block_hooks
1093+
);
1094+
}
10721095
}

0 commit comments

Comments
 (0)