From b86a12f64f28d6cf2b388dc6feb43b5902e9f440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Fri, 9 Sep 2022 10:01:05 +0200 Subject: [PATCH] Add tests --- .../custom-single-post-template.html | 3 ++ .../data/themedir1/block-theme/theme.json | 5 +++ tests/phpunit/tests/block-template-utils.php | 38 +++++++++++++++++++ .../tests/theme/wpThemeJsonResolver.php | 8 ++++ 4 files changed, 54 insertions(+) create mode 100644 tests/phpunit/data/themedir1/block-theme/templates/custom-single-post-template.html diff --git a/tests/phpunit/data/themedir1/block-theme/templates/custom-single-post-template.html b/tests/phpunit/data/themedir1/block-theme/templates/custom-single-post-template.html new file mode 100644 index 0000000000000..799062788c82b --- /dev/null +++ b/tests/phpunit/data/themedir1/block-theme/templates/custom-single-post-template.html @@ -0,0 +1,3 @@ + +

Custom Single Post template

+ \ No newline at end of file diff --git a/tests/phpunit/data/themedir1/block-theme/theme.json b/tests/phpunit/data/themedir1/block-theme/theme.json index 38fcb1d9dd65c..b4fc0500cc1e6 100644 --- a/tests/phpunit/data/themedir1/block-theme/theme.json +++ b/tests/phpunit/data/themedir1/block-theme/theme.json @@ -59,6 +59,11 @@ { "name": "page-home", "title": "Homepage template" + }, + { + "name": "custom-single-post-template", + "title": "Custom Single Post template", + "postTypes": ["post"] } ], "templateParts": [ diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index 666edd020a744..b20aff0955f95 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -12,6 +12,7 @@ */ class Tests_Block_Template_Utils extends WP_UnitTestCase { private static $post; + private static $custom_single_post_template_post; private static $template_part_post; private static $test_theme = 'block-theme'; @@ -50,6 +51,22 @@ public static function wpSetUpBeforeClass() { self::$post = self::factory()->post->create_and_get( $args ); wp_set_post_terms( self::$post->ID, self::$test_theme, 'wp_theme' ); + // Set up template post. + $args = array( + 'post_type' => 'wp_template', + 'post_name' => 'custom-single-post-template', + 'post_title' => 'Custom Single Post template (modified)', + 'post_content' => 'Content', + 'post_excerpt' => 'Description of custom single post template', + 'tax_input' => array( + 'wp_theme' => array( + self::$test_theme, + ), + ), + ); + self::$custom_single_post_template_post = self::factory()->post->create_and_get( $args ); + wp_set_post_terms( self::$custom_single_post_template_post->ID, self::$test_theme, 'wp_theme' ); + // Set up template part post. $template_part_args = array( 'post_type' => 'wp_template_part', @@ -319,6 +336,27 @@ static function( $template ) { $template_ids ); */ + + // Filter by post type. + $templates = get_block_templates( array( 'post_type' => 'post' ), 'wp_template' ); + $template_ids = get_template_ids( $templates ); + $this->assertSame( + array( + get_stylesheet() . '//' . 'my_template', + get_stylesheet() . '//' . 'custom-single-post-template', + ), + $template_ids + ); + + $templates = get_block_templates( array( 'post_type' => 'page' ), 'wp_template' ); + $template_ids = get_template_ids( $templates ); + $this->assertSame( + array( + get_stylesheet() . '//' . 'my_template', + get_stylesheet() . '//' . 'page-home', + ), + $template_ids + ); } /** diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 287e5d8aeb02f..e900e768e5938 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -159,6 +159,10 @@ public function test_translations_are_applied() { 'title' => 'Szablon strony głównej', 'postTypes' => array( 'page' ), ), + 'custom-single-post-template' => array( + 'title' => 'Custom Single Post template', + 'postTypes' => array( 'post' ), + ), ) ); $this->assertSame( @@ -338,6 +342,10 @@ function test_merges_child_theme_json_into_parent_theme_json() { 'title' => 'Homepage', 'postTypes' => array( 'page' ), ), + 'custom-single-post-template' => array( + 'title' => 'Custom Single Post template', + 'postTypes' => array( 'post' ), + ), ) ); }