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() {