123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * @group formatting
- */
- class Tests_Formatting_WPSpecialchars extends WP_UnitTestCase {
- function test_wp_specialchars_basics() {
- $html = "&<hello world>";
- $this->assertEquals( $html, _wp_specialchars( $html ) );
- $double = "&amp;&lt;hello world&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 = '&' . $ent . ';';
- $ent = '&' . $ent . ';';
- $this->assertEquals( $escaped, _wp_specialchars( $ent ) );
- }
- }
- function test_optionally_escapes_quotes() {
- $source = "\"'hello!'\"";
- $this->assertEquals( '"'hello!'"', _wp_specialchars($source, 'single') );
- $this->assertEquals( ""'hello!'"", _wp_specialchars($source, 'double') );
- $this->assertEquals( '"'hello!'"', _wp_specialchars($source, true) );
- $this->assertEquals( $source, _wp_specialchars($source) );
- }
- }
|