Files
wordpress-develop/tests/phpunit/tests/formatting/WPSpecialchars.php
T
Andrew Nacin 8045afd81b Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.

see #25088.


git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
2013-08-29 18:39:34 +00:00

43 lines
1.3 KiB
PHP

<?php
/**
* @group formatting
*/
class Tests_Formatting_WPSpecialchars extends WP_UnitTestCase {
function test_wp_specialchars_basics() {
$html = "&amp;&lt;hello world&gt;";
$this->assertEquals( $html, _wp_specialchars( $html ) );
$double = "&amp;amp;&amp;lt;hello world&amp;gt;";
$this->assertEquals( $double, _wp_specialchars( $html, ENT_NOQUOTES, false, true ) );
}
function test_allowed_entity_names() {
global $allowedentitynames;
// Allowed entities should be unchanged
foreach ( $allowedentitynames as $ent ) {
$ent = '&' . $ent . ';';
$this->assertEquals( $ent, _wp_specialchars( $ent ) );
}
}
function test_not_allowed_entity_names() {
$ents = array( 'iacut', 'aposs', 'pos', 'apo', 'apo?', 'apo.*', '.*apo.*', 'apos ', ' apos', ' apos ' );
foreach ( $ents as $ent ) {
$escaped = '&amp;' . $ent . ';';
$ent = '&' . $ent . ';';
$this->assertEquals( $escaped, _wp_specialchars( $ent ) );
}
}
function test_optionally_escapes_quotes() {
$source = "\"'hello!'\"";
$this->assertEquals( '"&#039;hello!&#039;"', _wp_specialchars($source, 'single') );
$this->assertEquals( "&quot;'hello!'&quot;", _wp_specialchars($source, 'double') );
$this->assertEquals( '&quot;&#039;hello!&#039;&quot;', _wp_specialchars($source, true) );
$this->assertEquals( $source, _wp_specialchars($source) );
}
}