-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Navigation Block: Fix erroneous escaping of ampersands (etc) #59561
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e5b6b78
Navigation Block: Add basic test coverage for Block Hooks
ockham 2528541
Fix post meta assertion
ockham 911d113
Get assertion to pass
ockham d08b830
Add assertion for get_the_content()
ockham 89ecc65
Use filter instead of action to avoid calling wp_update_post twice
ockham 6b263d4
Pass WP_Post object as context
ockham 97f900e
Set accepted_args to default of 1
ockham 68fe053
Fix unit test
ockham b0a04e9
Skip test on old WP versions
ockham 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 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,76 @@ | ||
<?php | ||
/** | ||
* Navigation block block hooks tests. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
*/ | ||
|
||
/** | ||
* Tests for the Navigation block. | ||
* | ||
* @group blocks | ||
*/ | ||
class Block_Navigation_Block_Hooks_Test extends WP_UnitTestCase { | ||
/** | ||
* Original markup. | ||
* | ||
* @var string | ||
*/ | ||
protected static $original_markup; | ||
|
||
/** | ||
* Post object. | ||
* | ||
* @var object | ||
*/ | ||
protected static $navigation_post; | ||
|
||
/** | ||
* Setup method. | ||
*/ | ||
public static function wpSetUpBeforeClass() { | ||
self::$original_markup = '<!-- wp:navigation-link {"label":"News & About","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} /-->'; | ||
|
||
self::$navigation_post = self::factory()->post->create_and_get( | ||
array( | ||
'post_type' => 'wp_navigation', | ||
'post_title' => 'Navigation Menu', | ||
'post_content' => self::$original_markup, | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
|
||
/** | ||
* @covers ::gutenberg_block_core_navigation_update_ignore_hooked_blocks_meta | ||
*/ | ||
public function test_block_core_navigation_update_ignore_hooked_blocks_meta() { | ||
register_block_type( | ||
'tests/my-block', | ||
array( | ||
'block_hooks' => array( | ||
'core/navigation' => 'last_child', | ||
), | ||
) | ||
); | ||
|
||
$post = get_post( self::$navigation_post ); | ||
|
||
gutenberg_block_core_navigation_update_ignore_hooked_blocks_meta( $post ); | ||
$this->assertSame( self::$original_markup . '<!-- wp:tests/my-block /-->', $post->post_content ); | ||
$this->assertSame( array( 'tests/my-block' ), get_post_meta( $post, '_wp_ignored_hooked_blocks' ) ); | ||
ockham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently failing, but apparently not because of #59516:
(Note that
&
is being escaped to\u0026amp;
, which seems correct. Most importantly, the leading slash is retained.)