From 3f5712a450a54ab184f526db7ae01595c59a2ac0 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 3 Jul 2024 19:41:21 +0400 Subject: [PATCH 1/7] Update escaping function --- includes/create-theme/theme-locale.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index 343b855e..1b4f0937 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -22,7 +22,7 @@ public static function escape_string( $string ) { } $string = addcslashes( $string, "'" ); - return "get( 'TextDomain' ) . "');?>"; + return "get( 'TextDomain' ) . "') );?>"; } /** From dcd1fc3627106fde283edba8a6b7c5bafd398618 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Wed, 3 Jul 2024 19:42:38 +0400 Subject: [PATCH 2/7] update tests --- tests/CbtThemeLocale/escapeString.php | 11 ++-- .../escapeTextContentOfBlocks.php | 36 ++++++------- tests/test-theme-templates.php | 50 +++++++++---------- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/tests/CbtThemeLocale/escapeString.php b/tests/CbtThemeLocale/escapeString.php index b9ff7361..0daedc61 100644 --- a/tests/CbtThemeLocale/escapeString.php +++ b/tests/CbtThemeLocale/escapeString.php @@ -13,29 +13,29 @@ class CBT_Theme_Locale_EscapeString extends CBT_Theme_Locale_UnitTestCase { public function test_escape_string() { $string = 'This is a test text.'; $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "", $escaped_string ); + $this->assertEquals( "", $escaped_string ); } public function test_escape_string_with_single_quote() { $string = "This is a test text with a single quote '"; $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "", $escaped_string ); + $this->assertEquals( "", $escaped_string ); } public function test_escape_string_with_double_quote() { $string = 'This is a test text with a double quote "'; $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "", $escaped_string ); + $this->assertEquals( "", $escaped_string ); } public function test_escape_string_with_html() { $string = '

This is a test text with HTML.

'; $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "This is a test text with HTML.

', 'test-locale-theme');?>", $escaped_string ); + $this->assertEquals( "This is a test text with HTML.

', 'test-locale-theme') );?>", $escaped_string ); } public function test_escape_string_with_already_escaped_string() { - $string = ""; + $string = ""; $escaped_string = CBT_Theme_Locale::escape_string( $string ); $this->assertEquals( $string, $escaped_string ); } @@ -46,3 +46,4 @@ public function test_escape_string_with_non_string() { $this->assertEquals( $string, $escaped_string ); } } + diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 7df7b62f..9c279c85 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -30,7 +30,7 @@ public function data_test_escape_text_content_of_blocks() { 'paragraph' => array( 'block_markup' => '

This is a test text.

', - 'expected_markup' => '

', + 'expected_markup' => '

', ), 'paragraph on nested groups' => array( @@ -46,7 +46,7 @@ public function data_test_escape_text_content_of_blocks() { '
-

+

', @@ -59,7 +59,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

+

', ), @@ -70,7 +70,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

+

', ), @@ -90,13 +90,13 @@ public function data_test_escape_text_content_of_blocks() { 'expected_markup' => ' ', ), @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
El polvo elemental que nos ignora
y que fue el rojo Adán y que es ahora
todos los hombres, y que no veremos.\', \'test-locale-theme\');?>
+
El polvo elemental que nos ignora
y que fue el rojo Adán y que es ahora
todos los hombres, y que no veremos.\', \'test-locale-theme\') );?>
', ), @@ -119,7 +119,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
+
', ), @@ -130,7 +130,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
<?php esc_html_e(\'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\');?>
+
<?php echo wp_kses_post( __(\'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\') );?>
', ), @@ -143,8 +143,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
<?php esc_html_e(\'Alternative text for cover image\', \'test-locale-theme\');?>
-

+
<?php echo wp_kses_post( __(\'Alternative text for cover image\', \'test-locale-theme\') );?>
+

', ), @@ -158,8 +158,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
<?php esc_html_e(\'This is alt text\', \'test-locale-theme\');?>
-

+
<?php echo wp_kses_post( __(\'This is alt text\', \'test-locale-theme\') );?>
+

', ), @@ -171,7 +171,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

+

', ), @@ -182,14 +182,10 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
+
', ), ); } } - - - - diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index 8ed6f10b..c4be5d49 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -6,13 +6,13 @@ class Test_Create_Block_Theme_Templates extends WP_UnitTestCase { /** - * Ensure that the string in a template is replaced with the appropraite PHP code + * Ensure that the string in a template is replaced with the appropriate PHP code */ public function test_paragraphs_are_localized() { $template = new stdClass(); $template->content = '

This is text to localize

'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "

", $new_template->content ); + $this->assertStringContainsString( "

", $new_template->content ); $this->assertStringNotContainsString( '

This is text to localize

', $new_template->content ); } @@ -37,7 +37,7 @@ public function test_paragraphs_in_groups_are_localized() {
'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'This is text to localize', $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

This is text to localize

', $new_template->content ); } @@ -49,7 +49,7 @@ public function test_buttons_are_localized() {
'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'This is text to localize', $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( 'This is text to localize', $new_template->content ); } @@ -61,7 +61,7 @@ public function test_headings_are_localized() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'This is a heading to localize.', $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

This is a heading to localize.

', $new_template->content ); } @@ -135,8 +135,8 @@ public function test_properly_encode_quotes_and_doublequotes() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - /* That looks like a mess, but what it should look like for REAL is */ - $this->assertStringContainsString( '', $escaped_template->content ); + /* That looks like a mess, but what it should look like for REAL is */ + $this->assertStringContainsString( "", $escaped_template->content ); } public function test_properly_encode_lessthan_and_greaterthan() { @@ -146,7 +146,7 @@ public function test_properly_encode_lessthan_and_greaterthan() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( ' is a <test>\', \'\');?>', $escaped_template->content ); + $this->assertStringContainsString( " is a <test>', '') );?>", $escaped_template->content ); } public function test_properly_encode_html_markup() { @@ -156,7 +156,7 @@ public function test_properly_encode_html_markup() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'Bold text has feelings <> TOO\', \'\');?>', $escaped_template->content ); + $this->assertStringContainsString( "Bold text has feelings <> TOO', '') );?>", $escaped_template->content ); } public function test_localize_alt_text_from_image() { @@ -167,7 +167,7 @@ public function test_localize_alt_text_from_image() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_alt_text_from_cover() { @@ -176,7 +176,7 @@ public function test_localize_alt_text_from_cover() {
- This is alt text + <?php echo wp_kses_post( __(\'This is alt text\', \'\') );?>

@@ -187,7 +187,7 @@ public function test_localize_alt_text_from_cover() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); // Check the markup attribute - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_quote() { @@ -201,8 +201,8 @@ public function test_localize_quote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_pullquote() { @@ -216,8 +216,8 @@ public function test_localize_pullquote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_list() { @@ -234,7 +234,7 @@ public function test_localize_list() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "
  • ", $new_template->content ); + $this->assertStringContainsString( "
  • ", $new_template->content ); } public function test_localize_verse() { @@ -243,7 +243,7 @@ public function test_localize_verse() {
    Here is some verse to localize
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "verse to localize', '');?>", $new_template->content ); + $this->assertStringContainsString( "verse to localize', '') );?>", $new_template->content ); } public function test_localize_table() { @@ -274,10 +274,10 @@ public function test_localize_table() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_media_text() { @@ -295,8 +295,8 @@ public function test_localize_media_text() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_cover_block_children() { @@ -314,7 +314,7 @@ public function test_localize_cover_block_children() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( '

    ', $new_template->content ); + $this->assertStringContainsString( "

    ", $new_template->content ); } public function test_localize_nested_cover_block_children() { From 0bc416393709dabeee8f9999476162fa839abaf5 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 4 Jul 2024 13:08:04 +0400 Subject: [PATCH 3/7] add method specific for attributes --- includes/create-theme/theme-locale.php | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index 1b4f0937..3d0b3510 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -5,12 +5,12 @@ class CBT_Theme_Locale { /** - * Escape a string for localization. + * Escape text for localization. * * @param string $string The string to escape. * @return string The escaped string. */ - public static function escape_string( $string ) { + private static function escape_text_content( $string ) { // Avoid escaping if the text is not a string. if ( ! is_string( $string ) ) { return $string; @@ -25,6 +25,27 @@ public static function escape_string( $string ) { return "get( 'TextDomain' ) . "') );?>"; } + /** + * Escape an html element attribute for localization. + * + * @param string $string The string to escape. + * @return string The escaped string. + */ + private static function escape_attribute( $string ) { + // Avoid escaping if the text is not a string. + if ( ! is_string( $string ) ) { + return $string; + } + + // Check if the text is already escaped. + if ( str_starts_with( $string, 'get( 'TextDomain' ) . "' );?>"; + } + /** * Get a replacement pattern for escaping the text from the html content of a block. * @@ -109,7 +130,7 @@ public static function escape_text_content_of_blocks( $blocks ) { return preg_replace_callback( $pattern, function( $matches ) { - return $matches[1] . self::escape_string( $matches[2] ) . $matches[3]; + return $matches[1] . self::escape_text_content( $matches[2] ) . $matches[3]; }, $content ); @@ -125,7 +146,7 @@ function( $matches ) { return preg_replace_callback( $pattern, function( $matches ) { - return 'alt="' . self::escape_string( $matches[1] ) . '"'; + return 'alt="' . self::escape_attribute( $matches[1] ) . '"'; }, $content ); From 86a18b2a340becda79adf3a52974f738aafe1ec8 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 4 Jul 2024 13:08:20 +0400 Subject: [PATCH 4/7] update tests --- includes/create-theme/theme-patterns.php | 2 +- tests/CbtThemeLocale/escapeString.php | 49 ------------------- .../escapeTextContentOfBlocks.php | 6 +-- tests/test-theme-templates.php | 8 +-- 4 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 tests/CbtThemeLocale/escapeString.php diff --git a/includes/create-theme/theme-patterns.php b/includes/create-theme/theme-patterns.php index e7de4890..5ff62fd6 100644 --- a/includes/create-theme/theme-patterns.php +++ b/includes/create-theme/theme-patterns.php @@ -38,7 +38,7 @@ public static function escape_alt_for_pattern( $html ) { public static function escape_text_for_pattern( $text ) { if ( $text && trim( $text ) !== '' ) { $escaped_text = addslashes( $text ); - return "get( 'Name' ) . "' ); ?>"; + return "get( 'Name' ) . "' ); ?>"; } } diff --git a/tests/CbtThemeLocale/escapeString.php b/tests/CbtThemeLocale/escapeString.php deleted file mode 100644 index 0daedc61..00000000 --- a/tests/CbtThemeLocale/escapeString.php +++ /dev/null @@ -1,49 +0,0 @@ -assertEquals( "", $escaped_string ); - } - - public function test_escape_string_with_single_quote() { - $string = "This is a test text with a single quote '"; - $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "", $escaped_string ); - } - - public function test_escape_string_with_double_quote() { - $string = 'This is a test text with a double quote "'; - $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "", $escaped_string ); - } - - public function test_escape_string_with_html() { - $string = '

    This is a test text with HTML.

    '; - $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( "This is a test text with HTML.

    ', 'test-locale-theme') );?>", $escaped_string ); - } - - public function test_escape_string_with_already_escaped_string() { - $string = ""; - $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( $string, $escaped_string ); - } - - public function test_escape_string_with_non_string() { - $string = null; - $escaped_string = CBT_Theme_Locale::escape_string( $string ); - $this->assertEquals( $string, $escaped_string ); - } -} - diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 9c279c85..59d86e44 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -130,7 +130,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php echo wp_kses_post( __(\'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\') );?>
    +
    <?php esc_attr_e( \'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\' );?>
    ', ), @@ -143,7 +143,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php echo wp_kses_post( __(\'Alternative text for cover image\', \'test-locale-theme\') );?>
    +
    <?php esc_attr_e( \'Alternative text for cover image\', \'test-locale-theme\' );?>

    ', @@ -158,7 +158,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php echo wp_kses_post( __(\'This is alt text\', \'test-locale-theme\') );?>
    +
    <?php esc_attr_e( \'This is alt text\', \'test-locale-theme\' );?>

    ', diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index c4be5d49..2f48d9f5 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -167,7 +167,7 @@ public function test_localize_alt_text_from_image() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_alt_text_from_cover() { @@ -176,7 +176,7 @@ public function test_localize_alt_text_from_cover() {
    - <?php echo wp_kses_post( __(\'This is alt text\', \'\') );?> + This is alt text

    @@ -187,7 +187,7 @@ public function test_localize_alt_text_from_cover() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); // Check the markup attribute - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_quote() { @@ -296,7 +296,7 @@ public function test_localize_media_text() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_cover_block_children() { From 3e53a9aa90c378d4e4a9d8424c3dc9248c804832 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Mon, 8 Jul 2024 14:05:09 -0500 Subject: [PATCH 5/7] Updates to only use wp_kses_post when strings contain html --- includes/create-theme/theme-locale.php | 20 +++++- .../escapeTextContentOfBlocks.php | 32 +++++----- tests/test-theme-templates.php | 63 ++++++++++++------- 3 files changed, 75 insertions(+), 40 deletions(-) diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index 3d0b3510..857a5745 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -16,13 +16,24 @@ private static function escape_text_content( $string ) { return $string; } + // Check if string is empty. + if ( '' === $string ) { + return $string; + } + // Check if the text is already escaped. if ( str_starts_with( $string, 'get( 'TextDomain' ) . "') );?>"; + + // Check if string contains html. + if ( strip_tags( $string ) !== $string ) { + return "get( 'TextDomain' ) . "' ) ); ?>"; + } + + return "get( 'TextDomain' ) . "' ); ?>"; } /** @@ -37,13 +48,18 @@ private static function escape_attribute( $string ) { return $string; } + // Check if string is empty. + if ( '' === $string ) { + return $string; + } + // Check if the text is already escaped. if ( str_starts_with( $string, 'get( 'TextDomain' ) . "' );?>"; + return "get( 'TextDomain' ) . "' ); ?>"; } /** diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 59d86e44..7ffb7c28 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -30,7 +30,7 @@ public function data_test_escape_text_content_of_blocks() { 'paragraph' => array( 'block_markup' => '

    This is a test text.

    ', - 'expected_markup' => '

    ', + 'expected_markup' => '

    ', ), 'paragraph on nested groups' => array( @@ -46,7 +46,7 @@ public function data_test_escape_text_content_of_blocks() { '
    -

    +

    ', @@ -59,7 +59,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -70,7 +70,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -90,13 +90,13 @@ public function data_test_escape_text_content_of_blocks() { 'expected_markup' => '
      -
    • +
    • -
    • +
    • -
    • +
    ', ), @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\') );?>
    +
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\' ) ); ?>
    ', ), @@ -119,7 +119,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    +
    ', ), @@ -130,7 +130,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\' );?>
    +
    <?php esc_attr_e( \'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\' ); ?>
    ', ), @@ -143,8 +143,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'Alternative text for cover image\', \'test-locale-theme\' );?>
    -

    +
    <?php esc_attr_e( \'Alternative text for cover image\', \'test-locale-theme\' ); ?>
    +

    ', ), @@ -158,8 +158,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'This is alt text\', \'test-locale-theme\' );?>
    -

    +
    <?php esc_attr_e( \'This is alt text\', \'test-locale-theme\' ); ?>
    +

    ', ), @@ -171,7 +171,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -182,7 +182,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    +
    ', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index 2f48d9f5..ce8fc79a 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -12,10 +12,18 @@ public function test_paragraphs_are_localized() { $template = new stdClass(); $template->content = '

    This is text to localize

    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "

    ", $new_template->content ); + $this->assertStringContainsString( "

    ", $new_template->content ); $this->assertStringNotContainsString( '

    This is text to localize

    ', $new_template->content ); } + public function test_empty_paragraphs_are_not_localized() { + $template = new stdClass(); + $template->content = '

    '; + $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); + $this->assertStringContainsString( '

    ', $new_template->content ); + $this->assertStringNotContainsString( 'esc_html_e', $new_template->content ); + } + /** * Ensure that escape_text_in_template is not called when the localizeText flag is set to false */ @@ -37,7 +45,7 @@ public function test_paragraphs_in_groups_are_localized() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

    This is text to localize

    ', $new_template->content ); } @@ -49,7 +57,7 @@ public function test_buttons_are_localized() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( 'This is text to localize', $new_template->content ); } @@ -61,7 +69,7 @@ public function test_headings_are_localized() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

    This is a heading to localize.

    ', $new_template->content ); } @@ -136,7 +144,7 @@ public function test_properly_encode_quotes_and_doublequotes() { $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); /* That looks like a mess, but what it should look like for REAL is */ - $this->assertStringContainsString( "", $escaped_template->content ); + $this->assertStringContainsString( "", $escaped_template->content ); } public function test_properly_encode_lessthan_and_greaterthan() { @@ -146,7 +154,7 @@ public function test_properly_encode_lessthan_and_greaterthan() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( " is a <test>', '') );?>", $escaped_template->content ); + $this->assertStringContainsString( " is a <test>', '' ); ?>", $escaped_template->content ); } public function test_properly_encode_html_markup() { @@ -156,7 +164,18 @@ public function test_properly_encode_html_markup() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "Bold text has feelings <> TOO', '') );?>", $escaped_template->content ); + $this->assertStringContainsString( "Bold text has feelings <> TOO', '' ) ); ?>", $escaped_template->content ); + } + + public function test_empty_alt_text_is_not_localized() { + $template = new stdClass(); + $template->content = ' + +
    + + '; + $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_alt_text_from_image() { @@ -167,7 +186,7 @@ public function test_localize_alt_text_from_image() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_alt_text_from_cover() { @@ -187,7 +206,7 @@ public function test_localize_alt_text_from_cover() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); // Check the markup attribute - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_quote() { @@ -201,8 +220,8 @@ public function test_localize_quote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_pullquote() { @@ -216,8 +235,8 @@ public function test_localize_pullquote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_list() { @@ -234,7 +253,7 @@ public function test_localize_list() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "
  • ", $new_template->content ); + $this->assertStringContainsString( "
  • ", $new_template->content ); } public function test_localize_verse() { @@ -243,7 +262,7 @@ public function test_localize_verse() {
    Here is some verse to localize
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "verse to localize', '') );?>", $new_template->content ); + $this->assertStringContainsString( "verse to localize', '' ) ); ?>", $new_template->content ); } public function test_localize_table() { @@ -274,10 +293,10 @@ public function test_localize_table() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_media_text() { @@ -295,8 +314,8 @@ public function test_localize_media_text() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_cover_block_children() { @@ -314,7 +333,7 @@ public function test_localize_cover_block_children() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "

    ", $new_template->content ); + $this->assertStringContainsString( "

    ", $new_template->content ); } public function test_localize_nested_cover_block_children() { From 75cc3d2a2026fbb0608dfbf700051ee44a423274 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 25 Jul 2024 13:07:48 -0300 Subject: [PATCH 6/7] remove wp_kses_post as escaping function --- includes/create-theme/theme-locale.php | 5 ----- tests/CbtThemeLocale/escapeTextContentOfBlocks.php | 2 +- tests/test-theme-templates.php | 6 +++--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index 857a5745..d5bb78a5 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -28,11 +28,6 @@ private static function escape_text_content( $string ) { $string = addcslashes( $string, "'" ); - // Check if string contains html. - if ( strip_tags( $string ) !== $string ) { - return "get( 'TextDomain' ) . "' ) ); ?>"; - } - return "get( 'TextDomain' ) . "' ); ?>"; } diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 7ffb7c28..296cb15d 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\' ) ); ?>
    +
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\' ); ?>
    ', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index ce8fc79a..0ab57e2c 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -143,7 +143,7 @@ public function test_properly_encode_quotes_and_doublequotes() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - /* That looks like a mess, but what it should look like for REAL is */ + /* That looks like a mess, but what it should look like for REAL is */ $this->assertStringContainsString( "", $escaped_template->content ); } @@ -164,7 +164,7 @@ public function test_properly_encode_html_markup() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "Bold text has feelings <> TOO', '' ) ); ?>", $escaped_template->content ); + $this->assertStringContainsString( "Bold text has feelings <> TOO', '' ); ?>", $escaped_template->content ); } public function test_empty_alt_text_is_not_localized() { @@ -262,7 +262,7 @@ public function test_localize_verse() {
    Here is some verse to localize
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "verse to localize', '' ) ); ?>", $new_template->content ); + $this->assertStringContainsString( "verse to localize', '' ); ?>", $new_template->content ); } public function test_localize_table() { From 90fe266094ac9b52fa8bebf9ee7478b3211bef36 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Fri, 30 Aug 2024 14:21:13 -0300 Subject: [PATCH 7/7] update tests --- includes/create-theme/theme-locale.php | 4 +- includes/create-theme/theme-patterns.php | 2 +- tests/CbtThemeLocale/escapeAttribute.php | 58 +++++++++++++++++++ tests/CbtThemeLocale/escapeTextContent.php | 56 ++++++++++++++++++ .../escapeTextContentOfBlocks.php | 32 +++++----- tests/test-theme-templates.php | 46 +++++++-------- 6 files changed, 156 insertions(+), 42 deletions(-) create mode 100644 tests/CbtThemeLocale/escapeAttribute.php create mode 100644 tests/CbtThemeLocale/escapeTextContent.php diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index d5bb78a5..783d8715 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -28,7 +28,7 @@ private static function escape_text_content( $string ) { $string = addcslashes( $string, "'" ); - return "get( 'TextDomain' ) . "' ); ?>"; + return "get( 'TextDomain' ) . "');?>"; } /** @@ -54,7 +54,7 @@ private static function escape_attribute( $string ) { } $string = addcslashes( $string, "'" ); - return "get( 'TextDomain' ) . "' ); ?>"; + return "get( 'TextDomain' ) . "');?>"; } /** diff --git a/includes/create-theme/theme-patterns.php b/includes/create-theme/theme-patterns.php index 5ff62fd6..23224c2d 100644 --- a/includes/create-theme/theme-patterns.php +++ b/includes/create-theme/theme-patterns.php @@ -38,7 +38,7 @@ public static function escape_alt_for_pattern( $html ) { public static function escape_text_for_pattern( $text ) { if ( $text && trim( $text ) !== '' ) { $escaped_text = addslashes( $text ); - return "get( 'Name' ) . "' ); ?>"; + return "get( 'Name' ) . "');?>"; } } diff --git a/tests/CbtThemeLocale/escapeAttribute.php b/tests/CbtThemeLocale/escapeAttribute.php new file mode 100644 index 00000000..9f511d06 --- /dev/null +++ b/tests/CbtThemeLocale/escapeAttribute.php @@ -0,0 +1,58 @@ +getMethod( $method_name ); + $method->setAccessible( true ); + return $method->invokeArgs( null, $args ); + } + + public function test_escape_attribute() { + $string = 'This is a test attribute.'; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $expected_string = "get( 'TextDomain' ) . "');?>"; + $this->assertEquals( $expected_string, $escaped_string ); + } + + public function test_escape_attribute_with_single_quote() { + $string = "This is a test attribute with a single quote '"; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $expected_string = "get( 'TextDomain' ) . "');?>"; + $this->assertEquals( $expected_string, $escaped_string ); + } + + public function test_escape_attribute_with_double_quote() { + $string = 'This is a test attribute with a double quote "'; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $expected_string = "get( 'TextDomain' ) . "');?>"; + $this->assertEquals( $expected_string, $escaped_string ); + } + + public function test_escape_attribute_with_empty_string() { + $string = ''; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $this->assertEquals( $string, $escaped_string ); + } + + public function test_escape_attribute_with_already_escaped_string() { + $string = "get( 'TextDomain' ) . "');?>"; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $this->assertEquals( $string, $escaped_string ); + } + + public function test_escape_attribute_with_non_string() { + $string = null; + $escaped_string = $this->call_private_method( 'escape_attribute', array( $string ) ); + $this->assertEquals( $string, $escaped_string ); + } +} diff --git a/tests/CbtThemeLocale/escapeTextContent.php b/tests/CbtThemeLocale/escapeTextContent.php new file mode 100644 index 00000000..32609243 --- /dev/null +++ b/tests/CbtThemeLocale/escapeTextContent.php @@ -0,0 +1,56 @@ +getMethod( $method_name ); + $method->setAccessible( true ); + return $method->invokeArgs( null, $args ); + } + + public function test_escape_text_content() { + $string = 'This is a test text.'; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( "", $escaped_string ); + } + + public function test_escape_text_content_with_single_quote() { + $string = "This is a test text with a single quote '"; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( "", $escaped_string ); + } + + public function test_escape_text_content_with_double_quote() { + $string = 'This is a test text with a double quote "'; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( "", $escaped_string ); + } + + public function test_escape_text_content_with_html() { + $string = '

    This is a test text with HTML.

    '; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( "This is a test text with HTML.

    ', 'test-locale-theme');?>", $escaped_string ); + } + + public function test_escape_text_content_with_already_escaped_string() { + $string = ""; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( $string, $escaped_string ); + } + + public function test_escape_text_content_with_non_string() { + $string = null; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $this->assertEquals( $string, $escaped_string ); + } +} diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 296cb15d..2fee4adf 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -30,7 +30,7 @@ public function data_test_escape_text_content_of_blocks() { 'paragraph' => array( 'block_markup' => '

    This is a test text.

    ', - 'expected_markup' => '

    ', + 'expected_markup' => '

    ', ), 'paragraph on nested groups' => array( @@ -46,7 +46,7 @@ public function data_test_escape_text_content_of_blocks() { '
    -

    +

    ', @@ -59,7 +59,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -70,7 +70,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -90,13 +90,13 @@ public function data_test_escape_text_content_of_blocks() { 'expected_markup' => '
      -
    • +
    • -
    • +
    • -
    • +
    ', ), @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\' ); ?>
    +
    El polvo elemental que nos ignora
    y que fue el rojo Adán y que es ahora
    todos los hombres, y que no veremos.\', \'test-locale-theme\');?>
    ', ), @@ -119,7 +119,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    +
    ', ), @@ -130,7 +130,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\' ); ?>
    +
    <?php esc_attr_e(\'Windows of a building in Nuremberg, Germany\', \'test-locale-theme\');?>
    ', ), @@ -143,8 +143,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'Alternative text for cover image\', \'test-locale-theme\' ); ?>
    -

    +
    <?php esc_attr_e(\'Alternative text for cover image\', \'test-locale-theme\');?>
    +

    ', ), @@ -158,8 +158,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    <?php esc_attr_e( \'This is alt text\', \'test-locale-theme\' ); ?>
    -

    +
    <?php esc_attr_e(\'This is alt text\', \'test-locale-theme\');?>
    +

    ', ), @@ -171,7 +171,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -

    +

    ', ), @@ -182,7 +182,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
    +
    ', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index 0ab57e2c..e2842800 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -12,7 +12,7 @@ public function test_paragraphs_are_localized() { $template = new stdClass(); $template->content = '

    This is text to localize

    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "

    ", $new_template->content ); + $this->assertStringContainsString( "

    ", $new_template->content ); $this->assertStringNotContainsString( '

    This is text to localize

    ', $new_template->content ); } @@ -45,7 +45,7 @@ public function test_paragraphs_in_groups_are_localized() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

    This is text to localize

    ', $new_template->content ); } @@ -57,7 +57,7 @@ public function test_buttons_are_localized() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( 'This is text to localize', $new_template->content ); } @@ -69,7 +69,7 @@ public function test_headings_are_localized() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); $this->assertStringNotContainsString( '

    This is a heading to localize.

    ', $new_template->content ); } @@ -143,8 +143,8 @@ public function test_properly_encode_quotes_and_doublequotes() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - /* That looks like a mess, but what it should look like for REAL is */ - $this->assertStringContainsString( "", $escaped_template->content ); + /* That looks like a mess, but what it should look like for REAL is */ + $this->assertStringContainsString( "", $escaped_template->content ); } public function test_properly_encode_lessthan_and_greaterthan() { @@ -154,7 +154,7 @@ public function test_properly_encode_lessthan_and_greaterthan() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( " is a <test>', '' ); ?>", $escaped_template->content ); + $this->assertStringContainsString( " is a <test>', '');?>", $escaped_template->content ); } public function test_properly_encode_html_markup() { @@ -164,7 +164,7 @@ public function test_properly_encode_html_markup() { '; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "Bold text has feelings <> TOO', '' ); ?>", $escaped_template->content ); + $this->assertStringContainsString( "Bold text has feelings <> TOO', '');?>", $escaped_template->content ); } public function test_empty_alt_text_is_not_localized() { @@ -186,7 +186,7 @@ public function test_localize_alt_text_from_image() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_alt_text_from_cover() { @@ -206,7 +206,7 @@ public function test_localize_alt_text_from_cover() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); // Check the markup attribute - $this->assertStringContainsString( 'alt=""', $new_template->content ); + $this->assertStringContainsString( 'alt=""', $new_template->content ); } public function test_localize_quote() { @@ -220,8 +220,8 @@ public function test_localize_quote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_pullquote() { @@ -235,8 +235,8 @@ public function test_localize_pullquote() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_list() { @@ -253,7 +253,7 @@ public function test_localize_list() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "
  • ", $new_template->content ); + $this->assertStringContainsString( "
  • ", $new_template->content ); } public function test_localize_verse() { @@ -262,7 +262,7 @@ public function test_localize_verse() {
    Here is some verse to localize
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "verse to localize', '' ); ?>", $new_template->content ); + $this->assertStringContainsString( "verse to localize', '');?>", $new_template->content ); } public function test_localize_table() { @@ -293,10 +293,10 @@ public function test_localize_table() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_media_text() { @@ -314,8 +314,8 @@ public function test_localize_media_text() {
    '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "", $new_template->content ); - $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); + $this->assertStringContainsString( "", $new_template->content ); } public function test_localize_cover_block_children() { @@ -333,7 +333,7 @@ public function test_localize_cover_block_children() { '; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "

    ", $new_template->content ); + $this->assertStringContainsString( "

    ", $new_template->content ); } public function test_localize_nested_cover_block_children() {