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() { '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', ), @@ -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' => ' - + ', ), @@ -143,8 +143,8 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -
y que fue el rojo Adán y que es ahora
todos los hombres, y que no veremos.\', \'test-locale-theme\');?>
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() {This is text to localize
', $new_template->content ); } @@ -57,7 +57,7 @@ public function test_buttons_are_localized() {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( "