mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
tests/phpunit/tests/blocks/applyBlockHooksToContentFromPostObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* Tests for the apply_block_hooks_to_content_from_post_object function. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
* | ||
* @since 6.8.0 | ||
* | ||
* @group blocks | ||
* @group block-hooks | ||
* | ||
* @covers ::apply_block_hooks_to_content_from_post_object | ||
*/ | ||
class Tests_Blocks_ApplyBlockHooksToContentFromPostObject extends WP_UnitTestCase { | ||
/** | ||
* Post object. | ||
* | ||
* @var WP_Post | ||
*/ | ||
protected static $post; | ||
|
||
/** | ||
* Post object. | ||
* | ||
* @var WP_Post | ||
*/ | ||
protected static $post_with_ignored_hooked_block; | ||
|
||
/** | ||
* | ||
* Set up. | ||
* | ||
* @ticket 62716 | ||
*/ | ||
public static function wpSetUpBeforeClass() { | ||
self::$post = self::factory()->post->create_and_get( | ||
array( | ||
'post_type' => 'post', | ||
'post_status' => 'publish', | ||
'post_title' => 'Test Post', | ||
'post_content' => '<!-- wp:heading {"level":1} --><h1>Hello World!</h1><!-- /wp:heading -->', | ||
) | ||
); | ||
|
||
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' => '<!-- wp:heading {"level":1} --><h1>Hello World!</h1><!-- /wp:heading -->', | ||
'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 = '<!-- wp:tests/hooked-block-first-child /-->' . | ||
self::$post->post_content . | ||
'<!-- wp:tests/hooked-block /-->'; | ||
$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 . '<!-- wp:tests/hooked-block /-->'; | ||
$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 ); | ||
} | ||
} |