diff --git a/phpunit/class-template-loader-test.php b/phpunit/class-template-loader-test.php deleted file mode 100644 index cb26c59db837ab..00000000000000 --- a/phpunit/class-template-loader-test.php +++ /dev/null @@ -1,205 +0,0 @@ - '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 ); - remove_filter( 'stylesheet_directory', array( __CLASS__, 'change_theme_directory' ) ); - remove_filter( 'template_directory', array( __CLASS__, 'change_theme_directory' ) ); - } - - public function tearDown() { - global $_wp_current_template_content; - unset( $_wp_current_template_content ); - } - - function test_gutenberg_page_home_block_template_takes_precedence_over_less_specific_block_templates() { - global $_wp_current_template_content; - $type = 'page'; - $templates = array( - 'page-home.php', - 'page-1.php', - 'page.php', - ); - $resolved_template_path = gutenberg_override_query_template( get_stylesheet_directory() . '/page-home.php', $type, $templates ); - $this->assertEquals( gutenberg_dir_path() . 'lib/template-canvas.php', $resolved_template_path ); - $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page-home.html', $_wp_current_template_content ); - } - - function test_gutenberg_page_block_template_takes_precedence() { - global $_wp_current_template_content; - $type = 'page'; - $templates = array( - 'page-slug-doesnt-exist.php', - 'page-1.php', - 'page.php', - ); - $resolved_template_path = gutenberg_override_query_template( get_stylesheet_directory() . '/page.php', $type, $templates ); - $this->assertEquals( gutenberg_dir_path() . 'lib/template-canvas.php', $resolved_template_path ); - $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page.html', $_wp_current_template_content ); - } - - function test_gutenberg_block_template_takes_precedence_over_equally_specific_php_template() { - global $_wp_current_template_content; - $type = 'index'; - $templates = array( - 'index.php', - ); - $resolved_template_path = gutenberg_override_query_template( get_stylesheet_directory() . '/index.php', $type, $templates ); - $this->assertEquals( gutenberg_dir_path() . 'lib/template-canvas.php', $resolved_template_path ); - $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/index.html', $_wp_current_template_content ); - } - - /** - * In a hybrid theme, a PHP template of higher specificity will take precedence over a block template - * with lower specificity. - * - * Covers https://github.com/WordPress/gutenberg/pull/29026. - */ - function test_gutenberg_more_specific_php_template_takes_precedence_over_less_specific_block_template() { - $page_id_template = 'page-1.php'; - $page_id_template_path = get_stylesheet_directory() . '/' . $page_id_template; - $type = 'page'; - $templates = array( - 'page-slug-doesnt-exist.php', - 'page-1.php', - 'page.php', - ); - $resolved_template_path = gutenberg_override_query_template( $page_id_template_path, $type, $templates ); - $this->assertEquals( $page_id_template_path, $resolved_template_path ); - } - - /** - * If a theme is a child of a block-based parent theme but has php templates for some of its pages, - * a php template of the child will take precedence over the parent's block template if they have - * otherwise equal specificity. - * - * Covers https://github.com/WordPress/gutenberg/pull/31123. - */ - function test_gutenberg_child_theme_php_template_takes_precedence_over_equally_specific_parent_theme_block_template() { - switch_theme( 'test-theme-child' ); - - $page_slug_template = 'page-home.php'; - $page_slug_template_path = get_stylesheet_directory() . '/' . $page_slug_template; - $type = 'page'; - $templates = array( - 'page-home.php', - 'page-1.php', - 'page.php', - ); - $resolved_template_path = gutenberg_override_query_template( $page_slug_template_path, $type, $templates ); - $this->assertEquals( $page_slug_template_path, $resolved_template_path ); - - switch_theme( 'test-theme' ); - } - - function test_gutenberg_child_theme_block_template_takes_precedence_over_equally_specific_parent_theme_php_template() { - global $_wp_current_template_content; - - switch_theme( 'test-theme-child' ); - - $page_template = 'page-1.php'; - $parent_theme_page_template_path = get_template_directory() . '/' . $page_template; - $type = 'page'; - $templates = array( - 'page-slug-doesnt-exist.php', - 'page-1.php', - 'page.php', - ); - $resolved_template_path = gutenberg_override_query_template( $parent_theme_page_template_path, $type, $templates ); - $this->assertEquals( gutenberg_dir_path() . 'lib/template-canvas.php', $resolved_template_path ); - $this->assertStringEqualsFile( get_stylesheet_directory() . '/templates/page-1.html', $_wp_current_template_content ); - - switch_theme( 'test-theme' ); - } - - /** - * Regression: https://github.com/WordPress/gutenberg/issues/31399. - */ - function test_gutenberg_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 = gutenberg_override_query_template( $custom_page_template_path, $type, $templates ); - $this->assertEquals( $custom_page_template_path, $resolved_template_path ); - } - - /** - * Covers: https://github.com/WordPress/gutenberg/pull/30438. - */ - function test_gutenberg_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 = gutenberg_override_query_template( $page_template_path, $type, $templates ); - $this->assertEquals( gutenberg_dir_path() . 'lib/template-canvas.php', $resolved_template_path ); - $this->assertEquals( self::$post->post_content, $_wp_current_template_content ); - } - - /** - * Regression: https://github.com/WordPress/gutenberg/issues/31652. - */ - function test_gutenberg_template_remains_unchanged_if_templates_array_is_empty() { - $resolved_template_path = gutenberg_override_query_template( '', 'search', array() ); - $this->assertEquals( '', $resolved_template_path ); - } - - static function change_theme_directory( $theme_dir, $theme ) { - return __DIR__ . '/fixtures/themes/' . $theme; - } -} diff --git a/phpunit/fixtures/themes/test-theme-child/page-home.php b/phpunit/fixtures/themes/test-theme-child/page-home.php deleted file mode 100644 index 86efe80db6afb3..00000000000000 --- a/phpunit/fixtures/themes/test-theme-child/page-home.php +++ /dev/null @@ -1,3 +0,0 @@ - -
Page (ID 1) Template
- \ No newline at end of file diff --git a/phpunit/fixtures/themes/test-theme/page-1.php b/phpunit/fixtures/themes/test-theme/page-1.php deleted file mode 100644 index eafbb1b6e854b0..00000000000000 --- a/phpunit/fixtures/themes/test-theme/page-1.php +++ /dev/null @@ -1,3 +0,0 @@ - -Index Template
- \ No newline at end of file diff --git a/phpunit/fixtures/themes/test-theme/templates/page-home.html b/phpunit/fixtures/themes/test-theme/templates/page-home.html deleted file mode 100644 index 6be0c70fb29c8d..00000000000000 --- a/phpunit/fixtures/themes/test-theme/templates/page-home.html +++ /dev/null @@ -1,3 +0,0 @@ - -Page (Home) Template
- \ No newline at end of file diff --git a/phpunit/fixtures/themes/test-theme/templates/page.html b/phpunit/fixtures/themes/test-theme/templates/page.html deleted file mode 100644 index 61c493e1bd8e88..00000000000000 --- a/phpunit/fixtures/themes/test-theme/templates/page.html +++ /dev/null @@ -1,3 +0,0 @@ - -Page Template
- \ No newline at end of file