mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-07 10:40:11 +00:00
Block Hooks: Set ignoredHookedBlocks metadata upon saving.
Decouple hooked blocks insertion from setting the `metadata.ignoredHookedBlocks` attribute on anchor blocks, and perform the latter step upon saving a template or template part to the database. This ensures that anchor blocks that have been newly added to a template (or part) on the client side will also get `ignoredHookedBlocks` metadata set correctly, thus preserving editor/front-end parity. Hooked block insertion, on the other hand, will continue to happen upon ''reading'' a template (or part). Props gziolo, tomjcafferkey. Fixes #60506. git-svn-id: https://develop.svn.wordpress.org/trunk@57627 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -25,20 +25,16 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 59572
|
||||
* @ticket 60126
|
||||
* @ticket 60506
|
||||
*
|
||||
* @covers ::insert_hooked_blocks
|
||||
*/
|
||||
public function test_insert_hooked_blocks_adds_metadata() {
|
||||
public function test_insert_hooked_blocks_returns_correct_markup() {
|
||||
$anchor_block = array(
|
||||
'blockName' => self::ANCHOR_BLOCK_TYPE,
|
||||
);
|
||||
|
||||
$actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
|
||||
$this->assertSame(
|
||||
array( self::HOOKED_BLOCK_TYPE ),
|
||||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
|
||||
"Hooked block type wasn't added to ignoredHookedBlocks metadata."
|
||||
);
|
||||
$this->assertSame(
|
||||
'<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /-->',
|
||||
$actual,
|
||||
@@ -49,10 +45,11 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 59572
|
||||
* @ticket 60126
|
||||
* @ticket 60506
|
||||
*
|
||||
* @covers ::insert_hooked_blocks
|
||||
*/
|
||||
public function test_insert_hooked_blocks_if_block_is_already_hooked() {
|
||||
public function test_insert_hooked_blocks_if_block_is_ignored() {
|
||||
$anchor_block = array(
|
||||
'blockName' => 'tests/anchor-block',
|
||||
'attrs' => array(
|
||||
@@ -63,11 +60,6 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
|
||||
$this->assertSame(
|
||||
array( self::HOOKED_BLOCK_TYPE ),
|
||||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
|
||||
"ignoredHookedBlocks metadata shouldn't have been modified."
|
||||
);
|
||||
$this->assertSame(
|
||||
'',
|
||||
$actual,
|
||||
@@ -78,10 +70,11 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 59572
|
||||
* @ticket 60126
|
||||
* @ticket 60506
|
||||
*
|
||||
* @covers ::insert_hooked_blocks
|
||||
*/
|
||||
public function test_insert_hooked_blocks_adds_to_ignored_hooked_blocks() {
|
||||
public function test_insert_hooked_blocks_if_other_block_is_ignored() {
|
||||
$anchor_block = array(
|
||||
'blockName' => 'tests/anchor-block',
|
||||
'attrs' => array(
|
||||
@@ -92,11 +85,6 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$actual = insert_hooked_blocks( $anchor_block, 'before', self::HOOKED_BLOCKS, array() );
|
||||
$this->assertSame(
|
||||
array( self::HOOKED_BLOCK_TYPE, self::OTHER_HOOKED_BLOCK_TYPE ),
|
||||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
|
||||
"Newly hooked block should've been added to ignoredHookedBlocks metadata while retaining previously ignored one."
|
||||
);
|
||||
$this->assertSame(
|
||||
'<!-- wp:' . self::OTHER_HOOKED_BLOCK_TYPE . ' /-->',
|
||||
$actual,
|
||||
@@ -107,6 +95,7 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 59572
|
||||
* @ticket 60126
|
||||
* @ticket 60506
|
||||
*
|
||||
* @covers ::insert_hooked_blocks
|
||||
*/
|
||||
@@ -139,11 +128,6 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
$actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
|
||||
remove_filter( 'hooked_block_' . self::HOOKED_BLOCK_TYPE, $filter, 10, 3 );
|
||||
|
||||
$this->assertSame(
|
||||
array( self::HOOKED_BLOCK_TYPE ),
|
||||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
|
||||
"Hooked block type wasn't added to ignoredHookedBlocks metadata."
|
||||
);
|
||||
$this->assertSame(
|
||||
'<!-- wp:' . self::HOOKED_BLOCK_TYPE . ' {"layout":{"type":"constrained"}} /-->',
|
||||
$actual,
|
||||
@@ -154,6 +138,7 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 59572
|
||||
* @ticket 60126
|
||||
* @ticket 60506
|
||||
*
|
||||
* @covers ::insert_hooked_blocks
|
||||
*/
|
||||
@@ -189,11 +174,6 @@ class Tests_Blocks_InsertHookedBlocks extends WP_UnitTestCase {
|
||||
$actual = insert_hooked_blocks( $anchor_block, 'after', self::HOOKED_BLOCKS, array() );
|
||||
remove_filter( 'hooked_block_' . self::HOOKED_BLOCK_TYPE, $filter, 10, 3 );
|
||||
|
||||
$this->assertSame(
|
||||
array( self::HOOKED_BLOCK_TYPE ),
|
||||
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'],
|
||||
"Hooked block type wasn't added to ignoredHookedBlocks metadata."
|
||||
);
|
||||
$this->assertSame(
|
||||
'<!-- wp:group --><div class="wp-block-group"><!-- wp:' . self::HOOKED_BLOCK_TYPE . ' /--></div><!-- /wp:group -->',
|
||||
$actual,
|
||||
|
||||
Reference in New Issue
Block a user