mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: resolve patterns server side.
See WordPress/gutenberg#60349. See WordPress/gutenberg#61757. See #6673. Fixes #61228. Props ellatrix, antonvlasenko. git-svn-id: https://develop.svn.wordpress.org/trunk@58303 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
4 changed files
with
161 additions
and
0 deletions.
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
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
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
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,72 @@ | ||
<?php | ||
/** | ||
* Tests for resolve_pattern_blocks. | ||
* | ||
* @package WordPress | ||
* @subpackage Blocks | ||
* | ||
* @since 6.6.0 | ||
* | ||
* @group blocks | ||
* @covers resolve_pattern_blocks | ||
*/ | ||
class Tests_Blocks_ResolvePatternBlocks extends WP_UnitTestCase { | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
register_block_pattern( | ||
'core/test', | ||
array( | ||
'title' => 'Test', | ||
'content' => '<!-- wp:paragraph -->Hello<!-- /wp:paragraph --><!-- wp:paragraph -->World<!-- /wp:paragraph -->', | ||
'description' => 'Test pattern.', | ||
) | ||
); | ||
register_block_pattern( | ||
'core/recursive', | ||
array( | ||
'title' => 'Recursive', | ||
'content' => '<!-- wp:paragraph -->Recursive<!-- /wp:paragraph --><!-- wp:pattern {"slug":"core/recursive"} /-->', | ||
'description' => 'Recursive pattern.', | ||
) | ||
); | ||
} | ||
|
||
public function tear_down() { | ||
unregister_block_pattern( 'core/test' ); | ||
unregister_block_pattern( 'core/recursive' ); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* @dataProvider data_should_resolve_pattern_blocks_as_expected | ||
* | ||
* @ticket 61228 | ||
* | ||
* @param string $blocks A string representing blocks that need resolving. | ||
* @param string $expected Expected result. | ||
*/ | ||
public function test_should_resolve_pattern_blocks_as_expected( $blocks, $expected ) { | ||
$actual = resolve_pattern_blocks( parse_blocks( $blocks ) ); | ||
$this->assertSame( $expected, serialize_blocks( $actual ) ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array | ||
*/ | ||
public function data_should_resolve_pattern_blocks_as_expected() { | ||
return array( | ||
// Works without attributes, leaves the block as is. | ||
'pattern with no slug attribute' => array( '<!-- wp:pattern /-->', '<!-- wp:pattern /-->' ), | ||
// Resolves the pattern. | ||
'test pattern' => array( '<!-- wp:pattern {"slug":"core/test"} /-->', '<!-- wp:paragraph -->Hello<!-- /wp:paragraph --><!-- wp:paragraph -->World<!-- /wp:paragraph -->' ), | ||
// Skips recursive patterns. | ||
'recursive pattern' => array( '<!-- wp:pattern {"slug":"core/recursive"} /-->', '<!-- wp:paragraph -->Recursive<!-- /wp:paragraph -->' ), | ||
// Resolves the pattern within a block. | ||
'pattern within a block' => array( '<!-- wp:group --><!-- wp:paragraph -->Before<!-- /wp:paragraph --><!-- wp:pattern {"slug":"core/test"} /--><!-- wp:paragraph -->After<!-- /wp:paragraph --><!-- /wp:group -->', '<!-- wp:group --><!-- wp:paragraph -->Before<!-- /wp:paragraph --><!-- wp:paragraph -->Hello<!-- /wp:paragraph --><!-- wp:paragraph -->World<!-- /wp:paragraph --><!-- wp:paragraph -->After<!-- /wp:paragraph --><!-- /wp:group -->' ), | ||
); | ||
} | ||
} |