From d47515c27439d3e25a490cf5a5876700a4b9b9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Mon, 18 Sep 2023 10:33:24 +0000 Subject: [PATCH] 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 --- .../data/blocks/hooked-block-error/block.json | 8 ++++++ tests/phpunit/data/blocks/notice/block.json | 5 +++- tests/phpunit/tests/blocks/register.php | 27 +++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/data/blocks/hooked-block-error/block.json diff --git a/tests/phpunit/data/blocks/hooked-block-error/block.json b/tests/phpunit/data/blocks/hooked-block-error/block.json new file mode 100644 index 0000000000..346c43b5b3 --- /dev/null +++ b/tests/phpunit/data/blocks/hooked-block-error/block.json @@ -0,0 +1,8 @@ +{ + "name": "tests/hooked-block-error", + "description": "A block that throws an error because it tries to hook a block to itself.", + "blockHooks": { + "tests/hooked-block-error": "before", + "tests/other-block": "after" + } +} diff --git a/tests/phpunit/data/blocks/notice/block.json b/tests/phpunit/data/blocks/notice/block.json index b6aa36e52e..909137252a 100644 --- a/tests/phpunit/data/blocks/notice/block.json +++ b/tests/phpunit/data/blocks/notice/block.json @@ -31,7 +31,10 @@ "root": ".wp-block-notice" }, "blockHooks": { - "core/post-content": "before" + "tests/before": "before", + "tests/after": "after", + "tests/first-child": "firstChild", + "tests/last-child": "lastChild" }, "supports": { "align": true, diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 55faf297a5..3e55206037 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -645,8 +645,13 @@ class Tests_Blocks_Register extends WP_UnitTestCase { 'Block type should contain selectors from metadata.' ); // @ticket 59346 - $this->assertSame( - array( 'core/post-content' => 'before' ), + $this->assertSameSets( + array( + 'tests/before' => 'before', + 'tests/after' => 'after', + 'tests/first-child' => 'first_child', + 'tests/last-child' => 'last_child', + ), $result->block_hooks, 'Block type should contain block hooks from metadata.' ); @@ -1069,4 +1074,22 @@ class Tests_Blocks_Register extends WP_UnitTestCase { $actual = register_block_style( 'core/query', $block_styles ); $this->assertTrue( $actual ); } + + /** + * @ticket 59346 + * + * @covers ::register_block_type + * + * @expectedIncorrectUsage register_block_type_from_metadata + */ + public function test_register_block_hooks_targeting_itself() { + $block_type = register_block_type( + DIR_TESTDATA . '/blocks/hooked-block-error' + ); + + $this->assertSame( + array( 'tests/other-block' => 'after' ), + $block_type->block_hooks + ); + } }