Skip to content

Commit 4685842

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 2e74c21 + dabab3f commit 4685842

File tree

2 files changed

+76
-74
lines changed

2 files changed

+76
-74
lines changed

tests/phpunit/tests/block-template-utils.php

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
class Tests_Block_Template_Utils extends WP_UnitTestCase {
1414
private static $post;
15-
private static $custom_single_post_template_post;
1615
private static $template_part_post;
1716
private static $test_theme = 'block-theme';
1817

@@ -51,22 +50,6 @@ public static function wpSetUpBeforeClass() {
5150
self::$post = self::factory()->post->create_and_get( $args );
5251
wp_set_post_terms( self::$post->ID, self::$test_theme, 'wp_theme' );
5352

54-
// Set up template post.
55-
$args = array(
56-
'post_type' => 'wp_template',
57-
'post_name' => 'custom-single-post-template',
58-
'post_title' => 'Custom Single Post template (modified)',
59-
'post_content' => 'Content',
60-
'post_excerpt' => 'Description of custom single post template',
61-
'tax_input' => array(
62-
'wp_theme' => array(
63-
self::$test_theme,
64-
),
65-
),
66-
);
67-
self::$custom_single_post_template_post = self::factory()->post->create_and_get( $args );
68-
wp_set_post_terms( self::$custom_single_post_template_post->ID, self::$test_theme, 'wp_theme' );
69-
7053
// Set up template part post.
7154
$template_part_args = array(
7255
'post_type' => 'wp_template_part',
@@ -95,7 +78,6 @@ public function set_up() {
9578

9679
public static function wpTearDownAfterClass() {
9780
wp_delete_post( self::$post->ID );
98-
wp_delete_post( self::$custom_single_post_template_post->ID );
9981
}
10082

10183
public function test_build_block_template_result_from_post() {
@@ -339,62 +321,6 @@ static function( $template ) {
339321
*/
340322
}
341323

342-
/**
343-
* @dataProvider data_get_block_template_should_respect_posttypes_property
344-
* @ticket 55881
345-
* @covers ::get_block_templates
346-
*
347-
* @param string $post_type Post type for query.
348-
* @param array $expected Expected template IDs.
349-
*/
350-
public function test_get_block_template_should_respect_posttypes_property( $post_type, $expected ) {
351-
$templates = get_block_templates( array( 'post_type' => $post_type ) );
352-
353-
$this->assertSame(
354-
$expected,
355-
$this->get_template_ids( $templates )
356-
);
357-
}
358-
359-
/**
360-
* Data provider.
361-
*
362-
* @return array
363-
*/
364-
public function data_get_block_template_should_respect_posttypes_property() {
365-
return array(
366-
'post' => array(
367-
'post_type' => 'post',
368-
'expected' => array(
369-
'block-theme//my_template',
370-
'block-theme//custom-single-post-template',
371-
),
372-
),
373-
'page' => array(
374-
'post_type' => 'page',
375-
'expected' => array(
376-
'block-theme//my_template',
377-
'block-theme//page-home',
378-
),
379-
),
380-
);
381-
}
382-
383-
/**
384-
* Gets the template IDs from the given array.
385-
*
386-
* @param object[] $templates Array of template objects to parse.
387-
* @return string[] The template IDs.
388-
*/
389-
private function get_template_ids( $templates ) {
390-
return array_map(
391-
static function( $template ) {
392-
return $template->id;
393-
},
394-
$templates
395-
);
396-
}
397-
398324
/**
399325
* Should flatten nested blocks
400326
*/

tests/phpunit/tests/blocks/getBlockTemplates.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class Tests_Blocks_GetBlockTemplates extends WP_UnitTestCase {
1313
*/
1414
private static $template;
1515

16+
/**
17+
* @var WP_Post
18+
*/
19+
private static $custom_single_post_template;
20+
1621
/**
1722
* @var WP_Post
1823
*/
@@ -39,6 +44,23 @@ public static function set_up_before_class() {
3944

4045
wp_set_post_terms( static::$template->ID, static::TEST_THEME, 'wp_theme' );
4146

47+
static::$custom_single_post_template = self::factory()->post->create_and_get(
48+
array(
49+
'post_type' => 'wp_template',
50+
'post_name' => 'custom-single-post-template',
51+
'post_title' => 'Custom Single Post template (modified)',
52+
'post_content' => 'Content',
53+
'post_excerpt' => 'Description of custom single post template',
54+
'tax_input' => array(
55+
'wp_theme' => array(
56+
static::TEST_THEME,
57+
),
58+
),
59+
)
60+
);
61+
62+
wp_set_post_terms( static::$custom_single_post_template->ID, static::TEST_THEME, 'wp_theme' );
63+
4264
/*
4365
* This template part has to have the same ID ("block-theme/small-header") as the template part
4466
* that is shipped with the "block-theme" theme. This is needed for testing purposes.
@@ -64,6 +86,7 @@ public static function set_up_before_class() {
6486

6587
public static function tear_down_after_class() {
6688
wp_delete_post( static::$template->ID );
89+
wp_delete_post( static::$custom_single_post_template->ID );
6790
wp_delete_post( static::$template_part->ID );
6891

6992
parent::tear_down_after_class();
@@ -113,4 +136,57 @@ public function data_get_block_templates_returns_unique_entities() {
113136
),
114137
);
115138
}
139+
140+
/**
141+
* @dataProvider data_get_block_templates_should_respect_posttypes_property
142+
* @ticket 55881
143+
*
144+
* @param string $post_type Post type for query.
145+
* @param array $expected Expected template IDs.
146+
*/
147+
public function test_get_block_templates_should_respect_posttypes_property( $post_type, $expected ) {
148+
$templates = get_block_templates( array( 'post_type' => $post_type ) );
149+
150+
$this->assertSameSets(
151+
$expected,
152+
$this->get_template_ids( $templates )
153+
);
154+
}
155+
156+
/**
157+
* Data provider.
158+
*
159+
* @return array
160+
*/
161+
public function data_get_block_templates_should_respect_posttypes_property() {
162+
return array(
163+
'post' => array(
164+
'post_type' => 'post',
165+
'expected' => array(
166+
'block-theme//custom-single-post-template',
167+
),
168+
),
169+
'page' => array(
170+
'post_type' => 'page',
171+
'expected' => array(
172+
'block-theme//page-home',
173+
),
174+
),
175+
);
176+
}
177+
178+
/**
179+
* Gets the template IDs from the given array.
180+
*
181+
* @param object[] $templates Array of template objects to parse.
182+
* @return string[] The template IDs.
183+
*/
184+
private function get_template_ids( $templates ) {
185+
return array_map(
186+
static function( $template ) {
187+
return $template->id;
188+
},
189+
$templates
190+
);
191+
}
116192
}

0 commit comments

Comments
 (0)