diff --git a/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php new file mode 100644 index 0000000000000..b8961cf5a9ec5 --- /dev/null +++ b/tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php @@ -0,0 +1,116 @@ +post->create_and_get( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_title' => 'Test Post', + 'post_content' => '

Hello World!

', + ) + ); + + self::$post_with_ignored_hooked_block = self::factory()->post->create_and_get( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_title' => 'Test Post', + 'post_content' => '

Hello World!

', + 'meta_input' => array( + '_wp_ignored_hooked_blocks' => '["tests/hooked-block-first-child"]', + ), + ) + ); + + register_block_type( + 'tests/hooked-block', + array( + 'block_hooks' => array( + 'core/heading' => 'after', + ), + ) + ); + + register_block_type( + 'tests/hooked-block-first-child', + array( + 'block_hooks' => array( + 'core/post-content' => 'first_child', + ), + ) + ); + } + + /** + * Tear down. + * + * @ticket 62716 + */ + public static function wpTearDownAfterClass() { + $registry = WP_Block_Type_Registry::get_instance(); + + $registry->unregister( 'tests/hooked-block' ); + $registry->unregister( 'tests/hooked-block-first-child' ); + } + + /** + * @ticket 62716 + */ + public function test_apply_block_hooks_to_content_from_post_object_inserts_hooked_block() { + $expected = '' . + self::$post->post_content . + ''; + $actual = apply_block_hooks_to_content_from_post_object( + self::$post->post_content, + self::$post, + 'insert_hooked_blocks' + ); + $this->assertSame( $expected, $actual ); + } + + /** + * @ticket 62716 + */ + public function test_apply_block_hooks_to_content_from_post_object_respects_ignored_hooked_blocks_post_meta() { + $expected = self::$post_with_ignored_hooked_block->post_content . ''; + $actual = apply_block_hooks_to_content_from_post_object( + self::$post_with_ignored_hooked_block->post_content, + self::$post_with_ignored_hooked_block, + 'insert_hooked_blocks' + ); + $this->assertSame( $expected, $actual ); + } +}