-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update escaping function * update tests * add method specific for attributes * update tests * Updates to only use wp_kses_post when strings contain html * remove wp_kses_post as escaping function * update tests --------- Co-authored-by: Grant Kinney <[email protected]>
- Loading branch information
1 parent
bbe5ca5
commit 6973cf8
Showing
7 changed files
with
185 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
require_once __DIR__ . '/base.php'; | ||
|
||
/** | ||
* Tests for the CBT_Theme_Locale::escape_attribute method. | ||
* | ||
* @package Create_Block_Theme | ||
* @covers CBT_Theme_Locale::escape_attribute | ||
* @group locale | ||
*/ | ||
class CBT_Theme_Locale_EscapeAttribute extends CBT_Theme_Locale_UnitTestCase { | ||
|
||
protected function call_private_method( $method_name, $args = array() ) { | ||
$reflection = new ReflectionClass( 'CBT_Theme_Locale' ); | ||
$method = $reflection->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 = "<?php esc_attr_e('This is a test attribute.', '" . wp_get_theme()->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 = "<?php esc_attr_e('This is a test attribute with a single quote \\'', '" . wp_get_theme()->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 = "<?php esc_attr_e('This is a test attribute with a double quote \"', '" . wp_get_theme()->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 = "<?php esc_attr_e('This is already escaped.', '" . wp_get_theme()->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 ); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/base.php'; | ||
|
||
/** | ||
* Tests for the CBT_Theme_Locale::escape_text_content method. | ||
* | ||
* @package Create_Block_Theme | ||
* @covers CBT_Theme_Locale::escape_text_content | ||
* @group locale | ||
*/ | ||
class CBT_Theme_Locale_EscapeTextContent extends CBT_Theme_Locale_UnitTestCase { | ||
|
||
protected function call_private_method( $method_name, $args = array() ) { | ||
$reflection = new ReflectionClass( 'CBT_Theme_Locale' ); | ||
$method = $reflection->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( "<?php esc_html_e('This is a test text.', 'test-locale-theme');?>", $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( "<?php esc_html_e('This is a test text with a single quote \\'', 'test-locale-theme');?>", $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( "<?php esc_html_e('This is a test text with a double quote \"', 'test-locale-theme');?>", $escaped_string ); | ||
} | ||
|
||
public function test_escape_text_content_with_html() { | ||
$string = '<p>This is a test text with HTML.</p>'; | ||
$escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); | ||
$this->assertEquals( "<?php esc_html_e('<p>This is a test text with HTML.</p>', 'test-locale-theme');?>", $escaped_string ); | ||
} | ||
|
||
public function test_escape_text_content_with_already_escaped_string() { | ||
$string = "<?php esc_html_e('This is a test text.', 'test-locale-theme');?>"; | ||
$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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.