WordPress.org

Make WordPress Core

Changeset 381 in tests


Ignore:
Timestamp:
07/29/11 20:37:56 (3 years ago)
Author:
ryan
Message:

special chars tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_formatting.php

    r380 r381  
    680680} 
    681681 
     682class TestWPSpecialchars extends WPTestCase { 
     683    function test_allowed_entity_names() { 
     684        global $allowedentitynames; 
     685 
     686        // Allowed entities should be unchanged 
     687        foreach ( $allowedentitynames as $ent ) { 
     688            $ent = '&' . $ent . ';'; 
     689            $this->assertEquals( $ent, _wp_specialchars( $ent ) ); 
     690        } 
     691    } 
     692 
     693    function test_not_allowed_entity_names() { 
     694        $ents = array( 'iacut', 'aposs', 'pos', 'apo', 'apo?', 'apo.*', '.*apo.*', 'apos ', ' apos' ); 
     695 
     696        foreach ( $ents as $ent ) { 
     697            $escaped = '&' . $ent . ';'; 
     698            $ent = '&' . $ent . ';'; 
     699            $this->assertEquals( $escaped, _wp_specialchars( $ent ) ); 
     700        } 
     701    } 
     702} 
     703 
    682704class TestEscAttr extends WPTestCase { 
    683705    function test_esc_attr_quotes() { 
     
    703725 
    704726    function test_esc_attr_amp() { 
    705         $out = esc_attr('foo & bar &baz; ''); 
    706         $this->assertEquals("foo & bar &baz; '", $out); 
     727        $out = esc_attr( 'foo & bar &baz; '' ); 
     728        $this->assertEquals( "foo & bar &baz; '", $out ); 
     729    } 
     730} 
     731 
     732class TestEscHtml extends WPTestCase { 
     733    function test_esc_html_basics() { 
     734        // Simple string 
     735        $html = "The quick brown fox."; 
     736        $this->assertEquals( $html, esc_html( $html ) ); 
     737 
     738        // URL with & 
     739        $html = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985"; 
     740        $escaped = "http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985"; 
     741        $this->assertEquals( $escaped, esc_html( $html ) ); 
     742 
     743        // SQL query 
     744        $html = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1"; 
     745        $escaped = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1"; 
     746        $this->assertEquals( $escaped, esc_html( $html ) ); 
    707747    } 
    708748} 
Note: See TracChangeset for help on using the changeset viewer.