From 194764cd45788b1739f0e1c1e2bf15ccfe23dfe6 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 10 Sep 2024 17:51:56 -0400 Subject: [PATCH] Update content with html test. Update remaining tests with inner markup. Try and fix tests. Format tests. --- includes/create-theme/theme-locale.php | 4 ++-- tests/CbtThemeLocale/escapeTextContent.php | 7 ++++--- .../CbtThemeLocale/escapeTextContentOfBlocks.php | 2 +- tests/test-theme-templates.php | 15 ++++++++++----- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/create-theme/theme-locale.php b/includes/create-theme/theme-locale.php index c50ffc43..ab7ed778 100644 --- a/includes/create-theme/theme-locale.php +++ b/includes/create-theme/theme-locale.php @@ -83,7 +83,7 @@ private static function escape_text_content( $string ) { // If tokens is not empty, format the string using sprintf. if ( ! empty( $tokens ) ) { // Format the string, replacing the placeholders with the formatted tokens. - return "get( 'TextDomain' ) . "' ), " . implode( + return "get( 'TextDomain' ) . "' ), " . implode( ', ', array_map( function( $token ) { @@ -91,7 +91,7 @@ function( $token ) { }, $tokens ) - ) . '); ?>'; + ) . ' ); ?>'; } return "get( 'TextDomain' ) . "');?>"; diff --git a/tests/CbtThemeLocale/escapeTextContent.php b/tests/CbtThemeLocale/escapeTextContent.php index 32609243..d3d0e4c4 100644 --- a/tests/CbtThemeLocale/escapeTextContent.php +++ b/tests/CbtThemeLocale/escapeTextContent.php @@ -37,9 +37,10 @@ public function test_escape_text_content_with_double_quote() { } 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 ); + $string = '

This is a test text with HTML.

'; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $expected_output = "', '

' ); ?>"; + $this->assertEquals( $expected_output, $escaped_string ); } public function test_escape_text_content_with_already_escaped_string() { diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 2fee4adf..34d705c6 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\');?>
+
\', \'
\', \'
\' ); ?>
', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index e2842800..f3aec6e6 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -159,12 +159,12 @@ public function test_properly_encode_lessthan_and_greaterthan() { public function test_properly_encode_html_markup() { $template = new stdClass(); - $template->content = ' -

Bold text has feelings <> TOO

- '; + $template->content = '

Bold text has feelings <> TOO

'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "Bold text has feelings <> TOO', '');?>", $escaped_template->content ); + $expected_output = '

\', \'\' ); ?>

'; + + $this->assertStringContainsString( $expected_output, $escaped_template->content ); } public function test_empty_alt_text_is_not_localized() { @@ -262,7 +262,12 @@ 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 ); + + $expected_output = ' +
\', \'\' ); ?>
+ '; + + $this->assertStringContainsString( $expected_output, $new_template->content ); } public function test_localize_table() {