forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock-template.php
More file actions
87 lines (78 loc) · 2.72 KB
/
block-template.php
File metadata and controls
87 lines (78 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Block_Template_Test class
*
* @package WordPress
*/
/**
* Tests for the block template loading algorithm.
*/
class Block_Template_Test extends WP_UnitTestCase {
private static $post;
private static $template_canvas_path = ABSPATH . WPINC . '/template-canvas.php';
public static function wpSetUpBeforeClass() {
// Set up custom template post.
$args = array(
'post_type' => 'wp_template',
'post_name' => 'wp-custom-template-my-block-template',
'post_title' => 'My Custom Block Template',
'post_content' => 'Content',
'post_excerpt' => 'Description of my block template',
'tax_input' => array(
'wp_theme' => array(
get_stylesheet(),
),
),
);
self::$post = self::factory()->post->create_and_get( $args );
wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' );
}
public static function wpTearDownAfterClass() {
wp_delete_post( self::$post->ID );
}
public function tearDown() {
global $_wp_current_template_content;
unset( $_wp_current_template_content );
}
/**
* Regression: https://github.com/WordPress/gutenberg/issues/31399.
*/
function test_custom_page_php_template_takes_precedence_over_all_other_templates() {
$custom_page_template = 'templates/full-width.php';
$custom_page_template_path = get_stylesheet_directory() . '/' . $custom_page_template;
$type = 'page';
$templates = array(
$custom_page_template,
'page-slug.php',
'page-1.php',
'page.php',
);
$resolved_template_path = locate_block_template( $custom_page_template_path, $type, $templates );
$this->assertSame( $custom_page_template_path, $resolved_template_path );
}
/**
* Covers: https://github.com/WordPress/gutenberg/pull/30438.
*/
function test_custom_page_block_template_takes_precedence_over_all_other_templates() {
global $_wp_current_template_content;
$custom_page_block_template = 'wp-custom-template-my-block-template';
$page_template_path = get_stylesheet_directory() . '/' . 'page.php';
$type = 'page';
$templates = array(
$custom_page_block_template,
'page-slug.php',
'page-1.php',
'page.php',
);
$resolved_template_path = locate_block_template( $page_template_path, $type, $templates );
$this->assertSame( self::$template_canvas_path, $resolved_template_path );
$this->assertSame( self::$post->post_content, $_wp_current_template_content );
}
/**
* Regression: https://github.com/WordPress/gutenberg/issues/31652.
*/
function test_template_remains_unchanged_if_templates_array_is_empty() {
$resolved_template_path = locate_block_template( '', 'search', array() );
$this->assertSame( '', $resolved_template_path );
}
}