From 0406e1151312cf41dcb479d56989a2daf651baa3 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 27 Jan 2014 03:15:29 +0000 Subject: [PATCH] Basic unit tests and additional documentation for wp_strip_all_tags(). props joehoyle. fixes #25507. git-svn-id: https://develop.svn.wordpress.org/trunk@27042 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 4 +++ .../tests/formatting/WPStripAllTags.php | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/phpunit/tests/formatting/WPStripAllTags.php diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index ed87b2b8ad..71f1794c52 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3568,6 +3568,10 @@ function normalize_whitespace( $str ) { /** * Properly strip all HTML tags including script and style + * + * This differs from strip_tags() because it removes the contents of + * the ' ) + * will return 'something'. wp_strip_all_tags will return '' * * @since 2.9.0 * diff --git a/tests/phpunit/tests/formatting/WPStripAllTags.php b/tests/phpunit/tests/formatting/WPStripAllTags.php new file mode 100644 index 0000000000..3af07b5709 --- /dev/null +++ b/tests/phpunit/tests/formatting/WPStripAllTags.php @@ -0,0 +1,33 @@ +ipsum'; + $this->assertEquals( 'loremipsum', wp_strip_all_tags( $text ) ); + + $text = "lorem
\nipsum"; + $this->assertEquals( "lorem\nipsum", wp_strip_all_tags( $text ) ); + + // test removing breaks is working + $text = "lorem
ipsum"; + $this->assertEquals( "loremipsum", wp_strip_all_tags( $text, true ) ); + + // test script / style tag's contents is removed + $text = "loremipsum"; + $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) ); + + $text = "loremipsum"; + $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) ); + + // test "marlformed" markup of contents + $text = "loremipsum"; + $this->assertEquals( "loremipsum", wp_strip_all_tags( $text ) ); + } +} +