Skip to content

Commit

Permalink
Block Themes: Ensure that _build_block_template_result_from_file() in…
Browse files Browse the repository at this point in the history
…jects theme attribute
  • Loading branch information
ockham committed Sep 11, 2023
1 parent 827a560 commit 3ce75ce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:group -->
<!-- wp:template-part {"slug":"header","align":"full", "tagName":"header","className":"site-header"} /-->
<!-- /wp:group -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:template-part {"slug":"header","theme":"fake-theme","align":"full", "tagName":"header","className":"site-header"} /-->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- wp:template-part {"slug":"header","align":"full", "tagName":"header","className":"site-header"} /-->
41 changes: 41 additions & 0 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,47 @@ public function test_build_block_template_result_from_file() {
$this->assertEmpty( $template_part->modified );
}

/**
* @dataProvider data_build_block_template_result_from_file_injects_theme_attribute
*/
public function test_build_block_template_result_from_file_injects_theme_attribute( $filename, $expected_content ) {
$template = _build_block_template_result_from_file(
array(
'slug' => 'single',
'path' => __DIR__ . '/../data/templates/' . $filename,
),
'wp_template'
);
$this->assertSame( $expected_content, $template->content );
}

public function data_build_block_template_result_from_file_injects_theme_attribute() {
$theme = 'block-theme';
return array(
array(
'template-with-template-part.html',
sprintf(
'<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->',
$theme
)
),
array(
'template-with-nested-template-part.html',
sprintf(
'<!-- wp:group -->
<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header","theme":"%s"} /-->
<!-- /wp:group -->',
$theme
)
),
array(
'template-with-template-part-with-existing-theme-attribute.html',
'<!-- wp:template-part {"slug":"header","theme":"fake-theme","align":"full", "tagName":"header","className":"site-header"} /-->'
),
);
}


public function test_inject_theme_attribute_in_block_template_content() {
$theme = get_stylesheet();
$content_without_theme_attribute = '<!-- wp:template-part {"slug":"header","align":"full", "tagName":"header","className":"site-header"} /-->';
Expand Down

0 comments on commit 3ce75ce

Please sign in to comment.