mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-02-27 19:22:45 +00:00
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
87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group block-templates
|
|
* @covers ::get_template_hierarchy
|
|
*/
|
|
abstract class WP_Block_Templates_UnitTestCase extends WP_UnitTestCase {
|
|
const TEST_THEME = 'block-theme';
|
|
|
|
protected static $template_post;
|
|
protected static $template_part_post;
|
|
|
|
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
/*
|
|
* Set up a template post corresponding to a different theme.
|
|
* Do this to ensure resolution and slug creation works as expected,
|
|
* even with another post of that same name present for another theme.
|
|
*/
|
|
self::$template_post = $factory->post->create_and_get(
|
|
array(
|
|
'post_type' => 'wp_template',
|
|
'post_name' => 'my_template',
|
|
'post_title' => 'My Template',
|
|
'post_content' => 'Content',
|
|
'post_excerpt' => 'Description of my template',
|
|
'tax_input' => array(
|
|
'wp_theme' => array(
|
|
'this-theme-should-not-resolve',
|
|
),
|
|
),
|
|
)
|
|
);
|
|
|
|
wp_set_post_terms( self::$template_post->ID, 'this-theme-should-not-resolve', 'wp_theme' );
|
|
|
|
// Set up template post.
|
|
self::$template_post = $factory->post->create_and_get(
|
|
array(
|
|
'post_type' => 'wp_template',
|
|
'post_name' => 'my_template',
|
|
'post_title' => 'My Template',
|
|
'post_content' => '<!-- wp:heading {"level":1,"metadata":{"ignoredHookedBlocks":["tests/ignored"]}} --><h1>Template</h1><!-- /wp:heading -->',
|
|
'post_excerpt' => 'Description of my template',
|
|
'tax_input' => array(
|
|
'wp_theme' => array(
|
|
self::TEST_THEME,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
|
|
wp_set_post_terms( self::$template_post->ID, self::TEST_THEME, 'wp_theme' );
|
|
|
|
// Set up template part post.
|
|
self::$template_part_post = $factory->post->create_and_get(
|
|
array(
|
|
'post_type' => 'wp_template_part',
|
|
'post_name' => 'my_template_part',
|
|
'post_title' => 'My Template Part',
|
|
'post_content' => '<!-- wp:heading {"level":2,"metadata":{"ignoredHookedBlocks":["tests/ignored"]}} --><h2>Template Part</h2><!-- /wp:heading -->',
|
|
'post_excerpt' => 'Description of my template part',
|
|
'tax_input' => array(
|
|
'wp_theme' => array(
|
|
self::TEST_THEME,
|
|
),
|
|
'wp_template_part_area' => array(
|
|
WP_TEMPLATE_PART_AREA_HEADER,
|
|
),
|
|
),
|
|
)
|
|
);
|
|
|
|
wp_set_post_terms( self::$template_part_post->ID, WP_TEMPLATE_PART_AREA_HEADER, 'wp_template_part_area' );
|
|
wp_set_post_terms( self::$template_part_post->ID, self::TEST_THEME, 'wp_theme' );
|
|
}
|
|
|
|
public static function wpTearDownAfterClass() {
|
|
wp_delete_post( self::$template_post->ID );
|
|
wp_delete_post( self::$template_part_post->ID );
|
|
}
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
switch_theme( self::TEST_THEME );
|
|
}
|
|
}
|