Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use data provider
  • Loading branch information
Mamaduka committed Nov 30, 2021
commit 80bbb6d24fc2d3b3413967195868b9c425f13583
47 changes: 27 additions & 20 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,34 @@ function test_inject_theme_attribute_in_block_template_content() {

/**
* @ticket 54448
*
* @dataProvider data_remove_theme_attribute_in_block_template_content
*/
function test_remove_theme_attribute_in_block_template_content() {
$content_with_existing_theme_attribute = '<!-- wp:template-part {"slug":"header","theme":"tt1-blocks","align":"full","tagName":"header","className":"site-header"} /-->';
$template_content = _remove_theme_attribute_in_block_template_content( $content_with_existing_theme_attribute );
$expected = '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->';
$this->assertEquals( $expected, $template_content );

$content_with_existing_theme_attribute_nested = '<!-- wp:group --><!-- wp:template-part {"slug":"header","theme":"tt1-blocks","align":"full","tagName":"header","className":"site-header"} /--><!-- /wp:group -->';
$template_content = _remove_theme_attribute_in_block_template_content( $content_with_existing_theme_attribute_nested );
$expected = '<!-- wp:group --><!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /--><!-- /wp:group -->';
$this->assertEquals( $expected, $template_content );

// Does not modify content when there is no existing theme attribute.
$content_without_theme_attribute = '<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->';
$template_content = _remove_theme_attribute_in_block_template_content( $content_without_theme_attribute );
$this->assertEquals( $content_without_theme_attribute, $template_content );

// Does not remove theme when there is no template part.
$content_with_no_template_part = '<!-- wp:post-content /-->';
$template_content = _remove_theme_attribute_in_block_template_content( $content_with_no_template_part );
$this->assertEquals( $content_with_no_template_part, $template_content );
function test_remove_theme_attribute_in_block_template_content( $template_content, $expected ) {
$this->assertEquals( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );
$this->assertSame( $expected, _remove_theme_attribute_in_block_template_content( $template_content ) );

}

function data_remove_theme_attribute_in_block_template_content() {
return array(
array(
'<!-- wp:template-part {"slug":"header","theme":"tt1-blocks","align":"full","tagName":"header","className":"site-header"} /-->',
'<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->',
),
array(
'<!-- wp:group --><!-- wp:template-part {"slug":"header","theme":"tt1-blocks","align":"full","tagName":"header","className":"site-header"} /--><!-- /wp:group -->',
'<!-- wp:group --><!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /--><!-- /wp:group -->',
),
// Does not modify content when there is no existing theme attribute.
array(
'<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->',
'<!-- wp:template-part {"slug":"header","align":"full","tagName":"header","className":"site-header"} /-->',
),
// Does not remove theme when there is no template part.
array(
'<!-- wp:post-content /-->',
'<!-- wp:post-content /-->',
),
);
}

/**
Expand Down