diff --git a/tests/phpunit/data/templates/template-with-nested-template-part.html b/tests/phpunit/data/templates/template-with-nested-template-part.html new file mode 100644 index 0000000000..7df8341fe5 --- /dev/null +++ b/tests/phpunit/data/templates/template-with-nested-template-part.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html b/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html new file mode 100644 index 0000000000..d5f92e7d11 --- /dev/null +++ b/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/phpunit/data/templates/template-with-template-part.html b/tests/phpunit/data/templates/template-with-template-part.html new file mode 100644 index 0000000000..ccec47b648 --- /dev/null +++ b/tests/phpunit/data/templates/template-with-template-part.html @@ -0,0 +1 @@ + \ 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 b5587def99..7c5e8dd595 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -161,6 +161,64 @@ class Tests_Block_Template_Utils extends WP_UnitTestCase { $this->assertEmpty( $template_part->modified ); } + /** + * @ticket 59325 + * + * @covers ::_build_block_template_result_from_file + * + * @dataProvider data_build_block_template_result_from_file_injects_theme_attribute + * + * @param string $filename The template's filename. + * @param string $expected The expected block markup. + */ + public function test_build_block_template_result_from_file_injects_theme_attribute( $filename, $expected ) { + $template = _build_block_template_result_from_file( + array( + 'slug' => 'single', + 'path' => DIR_TESTDATA . "/templates/$filename", + ), + 'wp_template' + ); + $this->assertSame( $expected, $template->content ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_build_block_template_result_from_file_injects_theme_attribute() { + $theme = 'block-theme'; + return array( + 'a template with a template part block' => array( + 'filename' => 'template-with-template-part.html', + 'expected' => sprintf( + '', + $theme + ), + ), + 'a template with a template part block nested inside another block' => array( + 'filename' => 'template-with-nested-template-part.html', + 'expected' => sprintf( + ' + +', + $theme + ), + ), + 'a template with a template part block with an existing theme attribute' => array( + 'filename' => 'template-with-template-part-with-existing-theme-attribute.html', + 'expected' => '', + ), + 'a template with no template part block' => array( + 'filename' => 'template.html', + 'expected' => ' +
Just a paragraph
+', + ), + ); + } + public function test_inject_theme_attribute_in_block_template_content() { $theme = get_stylesheet(); $content_without_theme_attribute = '';