From 4e6823d17ccd924780d55b3c2265552f15ae1e01 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 3 Dec 2021 16:57:19 +0000 Subject: [PATCH] Editor: Enable incomplete unit tests in `Tests_Block_Template_Utils:: test_get_block_template_from_file()`. At the time tests were backported from Gutenberg, a block template theme was not available in the test suite; thus, the test was marked as `markTestIncomplete()`. Now that `block-theme` and `block-theme-child` test fixture block template themes are available, this commit removes the `markTestIncomplete()` and adjusts the test to run by switching to the `block-theme` test fixture. Follow-up to [51003], [52062], [52247]. Props bernhard-reiter. Fixes #54551. git-svn-id: https://develop.svn.wordpress.org/trunk@52314 602fd350-edb4-49c9-b593-d223f7449a82 --- .../block-theme/parts/small-header.html | 3 +++ tests/phpunit/tests/block-template-utils.php | 26 +++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 tests/phpunit/data/themedir1/block-theme/parts/small-header.html diff --git a/tests/phpunit/data/themedir1/block-theme/parts/small-header.html b/tests/phpunit/data/themedir1/block-theme/parts/small-header.html new file mode 100644 index 0000000000..5c18e98125 --- /dev/null +++ b/tests/phpunit/data/themedir1/block-theme/parts/small-header.html @@ -0,0 +1,3 @@ + +

Small Header Template Part

+ \ No newline at end of file diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index fc382862a8..f373480c0d 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -13,11 +13,9 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { private static $post; private static $template_part_post; + private static $test_theme = 'block-theme'; public static function wpSetUpBeforeClass() { - // We may need a block theme. - // switch_theme( 'tt1-blocks' ); - // Set up a template post corresponding to a different theme. // We do this to ensure resolution and slug creation works as expected, // even with another post of that same name present for another theme. @@ -45,12 +43,12 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { 'post_excerpt' => 'Description of my template', 'tax_input' => array( 'wp_theme' => array( - get_stylesheet(), + self::$test_theme, ), ), ); self::$post = self::factory()->post->create_and_get( $args ); - wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' ); + wp_set_post_terms( self::$post->ID, self::$test_theme, 'wp_theme' ); // Set up template part post. $template_part_args = array( @@ -61,7 +59,7 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { 'post_excerpt' => 'Description of my template part', 'tax_input' => array( 'wp_theme' => array( - get_stylesheet(), + self::$test_theme, ), 'wp_template_part_area' => array( WP_TEMPLATE_PART_AREA_HEADER, @@ -70,7 +68,12 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { ); self::$template_part_post = self::factory()->post->create_and_get( $template_part_args ); 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, get_stylesheet(), 'wp_theme' ); + wp_set_post_terms( self::$template_part_post->ID, self::$test_theme, 'wp_theme' ); + } + + public function set_up() { + parent::set_up(); + switch_theme( self::$test_theme ); } public static function wpTearDownAfterClass() { @@ -225,9 +228,7 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { * Should retrieve the template from the theme files. */ function test_get_block_template_from_file() { - $this->markTestIncomplete(); - // Requires switching to a block theme. - /* $id = get_stylesheet() . '//' . 'index'; + $id = get_stylesheet() . '//' . 'index'; $template = get_block_template( $id, 'wp_template' ); $this->assertSame( $id, $template->id ); $this->assertSame( get_stylesheet(), $template->theme ); @@ -237,16 +238,15 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { $this->assertSame( 'wp_template', $template->type ); // Test template parts. - $id = get_stylesheet() . '//' . 'header'; + $id = get_stylesheet() . '//' . 'small-header'; $template = get_block_template( $id, 'wp_template_part' ); $this->assertSame( $id, $template->id ); $this->assertSame( get_stylesheet(), $template->theme ); - $this->assertSame( 'header', $template->slug ); + $this->assertSame( 'small-header', $template->slug ); $this->assertSame( 'publish', $template->status ); $this->assertSame( 'theme', $template->source ); $this->assertSame( 'wp_template_part', $template->type ); $this->assertSame( WP_TEMPLATE_PART_AREA_HEADER, $template->area ); - */ } /**