-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block Hooks API: Move ignoredHookedBlocks metadata injection logic #6604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tjcafferkey
wants to merge
1
commit into
WordPress:trunk
from
tjcafferkey:update/ignored-hooked-blocks-metadata
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
196 changes: 196 additions & 0 deletions
196
tests/phpunit/tests/blocks/updateIgnoredHookedBlocksPostMeta.php
This file contains hidden or 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,196 @@ | ||
| <?php | ||
| /** | ||
| * Tests for update_ignored_hooked_blocks_postmeta | ||
| * | ||
| * @package WordPress | ||
| * @subpackage Blocks | ||
| * | ||
| * @since 6.6.0 | ||
| * | ||
| * @group blocks | ||
ockham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @covers ::update_ignored_hooked_blocks_postmeta | ||
| */ | ||
| class Tests_Blocks_UpdateIgnoredHookedBlocksPostMeta extends WP_UnitTestCase { | ||
| /** | ||
| * Post object. | ||
| * | ||
| * @var object | ||
| */ | ||
| protected static $navigation_post; | ||
|
|
||
| /** | ||
| * Setup method. | ||
| */ | ||
| public static function wpSetUpBeforeClass() { | ||
| self::$navigation_post = self::factory()->post->create_and_get( | ||
| array( | ||
| 'post_type' => 'wp_navigation', | ||
| 'post_title' => 'Navigation Menu', | ||
| 'post_content' => 'Original content', | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tear down each test method. | ||
| */ | ||
| public function tear_down() { | ||
| $registry = WP_Block_Type_Registry::get_instance(); | ||
|
|
||
| if ( $registry->is_registered( 'tests/my-block' ) ) { | ||
| $registry->unregister( 'tests/my-block' ); | ||
| } | ||
|
|
||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60759 | ||
| */ | ||
| public function test_update_ignored_hooked_blocks_postmeta_preserves_entities() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/navigation' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $original_markup = '<!-- wp:navigation-link {"label":"News & About","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->'; | ||
| $post = new stdClass(); | ||
| $post->ID = self::$navigation_post->ID; | ||
| $post->post_content = $original_markup; | ||
| $post->post_type = 'wp_navigation'; | ||
|
|
||
| $post = update_ignored_hooked_blocks_postmeta( $post ); | ||
|
|
||
| // We expect the '&' character to be replaced with its unicode representation. | ||
| $expected_markup = str_replace( '&', '\u0026', $original_markup ); | ||
|
|
||
| $this->assertSame( | ||
| $expected_markup, | ||
| $post->post_content, | ||
| 'Post content did not match expected markup with entities escaped.' | ||
| ); | ||
| $this->assertSame( | ||
| array( 'tests/my-block' ), | ||
| json_decode( get_post_meta( self::$navigation_post->ID, '_wp_ignored_hooked_blocks', true ), true ), | ||
| 'Block was not added to ignored hooked blocks metadata.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60759 | ||
| */ | ||
| public function test_update_ignored_hooked_blocks_postmeta_dont_modify_no_post_id() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/navigation' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $original_markup = '<!-- wp:navigation-link {"label":"News","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->'; | ||
| $post = new stdClass(); | ||
| $post->post_content = $original_markup; | ||
| $post->post_type = 'wp_navigation'; | ||
|
|
||
| $post = update_ignored_hooked_blocks_postmeta( $post ); | ||
|
|
||
| $this->assertSame( | ||
| $original_markup, | ||
| $post->post_content, | ||
| 'Post content did not match the original markup.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60759 | ||
| */ | ||
| public function test_update_ignored_hooked_blocks_postmeta_retains_content_if_not_set() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/navigation' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $post = new stdClass(); | ||
| $post->ID = self::$navigation_post->ID; | ||
| $post->post_title = 'Navigation Menu with changes'; | ||
| $post->post_type = 'wp_navigation'; | ||
|
|
||
| $post = update_ignored_hooked_blocks_postmeta( $post ); | ||
|
|
||
| $this->assertSame( | ||
| 'Navigation Menu with changes', | ||
| $post->post_title, | ||
| 'Post title was changed.' | ||
| ); | ||
|
|
||
| $this->assertFalse( | ||
| isset( $post->post_content ), | ||
| 'Post content should not be set.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60759 | ||
| */ | ||
| public function test_update_ignored_hooked_blocks_postmeta_dont_modify_if_not_navigation() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/navigation' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $original_markup = '<!-- wp:navigation-link {"label":"News","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->'; | ||
| $post = new stdClass(); | ||
| $post->ID = self::$navigation_post->ID; | ||
| $post->post_content = $original_markup; | ||
| $post->post_type = 'post'; | ||
|
|
||
| $post = update_ignored_hooked_blocks_postmeta( $post ); | ||
|
|
||
| $this->assertSame( | ||
| $original_markup, | ||
| $post->post_content, | ||
| 'Post content did not match the original markup.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 60759 | ||
| */ | ||
| public function test_update_ignored_hooked_blocks_postmeta_dont_modify_if_no_post_type() { | ||
| register_block_type( | ||
| 'tests/my-block', | ||
| array( | ||
| 'block_hooks' => array( | ||
| 'core/navigation' => 'last_child', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $original_markup = '<!-- wp:navigation-link {"label":"News","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->'; | ||
| $post = new stdClass(); | ||
| $post->ID = self::$navigation_post->ID; | ||
| $post->post_content = $original_markup; | ||
|
|
||
| $post = update_ignored_hooked_blocks_postmeta( $post ); | ||
|
|
||
| $this->assertSame( | ||
| $original_markup, | ||
| $post->post_content, | ||
| 'Post content did not match the original markup.' | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.