WordPress.org

Make WordPress Core

Changeset 331 in tests


Ignore:
Timestamp:
01/26/2011 08:36:44 PM (7 years ago)
Author:
duck_
Message:

Formatting tests: js_escape and clean_url are deprecated, remove old knownWPBug requests, remove TestMakeClickable for now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_formatting.php

    r320 r331  
    66        $this->assertEquals($in, make_clickable($in));
    77    }
    8    
     8
    99    function test_valid_mailto() {
    10        
    1110        $valid_emails = array(
    1211            'foo@example.com',
     
    1918            $this->assertEquals('<a href="mailto:'.$email.'">'.$email.'</a>', make_clickable($email));
    2019        }
    21        
    22     }
    23    
     20    }
     21
    2422    function test_invalid_mailto() {
    25        
    2623        $invalid_emails = array(
    2724            'foo',
     
    3532            $this->assertEquals($email, make_clickable($email));
    3633        }
    37        
    38     }
    39    
    40     // tests that make_clickable will not link trailing periods, commas and
     34    }
     35
     36    // tests that make_clickable will not link trailing periods, commas and
    4137    // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
    4238    function test_strip_trailing_with_protocol() {
     
    6359    }
    6460
    65     // tests that make_clickable will not link trailing periods, commas and 
     61    // tests that make_clickable will not link trailing periods, commas and
    6662    // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
    6763    function test_strip_trailing_with_protocol_nothing_afterwards() {
     
    8884            $this->assertEquals($urls_expected[$key], make_clickable($url));
    8985        }
    90     }   
    91    
    92     // tests that make_clickable will not link trailing periods, commas and 
     86    }
     87
     88    // tests that make_clickable will not link trailing periods, commas and
    9389    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
    9490    function test_strip_trailing_without_protocol() {
     
    115111    }
    116112
    117     // tests that make_clickable will not link trailing periods, commas and 
     113    // tests that make_clickable will not link trailing periods, commas and
    118114    // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
    119115    function test_strip_trailing_without_protocol_nothing_afterwards() {
     
    138134            $this->assertEquals($urls_expected[$key], make_clickable($url));
    139135        }
    140     }   
    141    
     136    }
     137
     138    // #4570
    142139    function test_iri() {
    143         $this->knownWPBug(4570);
    144140        $urls_before = array(
    145141            'http://www.詹姆斯.com/',
     
    156152        }
    157153    }
    158    
     154
     155    // #10990
    159156    function test_brackets_in_urls() {
    160         $this->knownWPBug(10990);
    161157        $urls_before = array(
    162158            'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)',
     
    179175            'blah blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
    180176            'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.) blah blah',
    181             'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.)moreurl blah blah',     
    182         );
    183         foreach ($urls_before as $key => $url) {
    184             $this->assertEquals($urls_expected[$key], make_clickable($url));
    185         }
    186     }
    187 
    188     // Based on a real comments which were incorrectly linked.
     177            'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.)moreurl blah blah',
     178        );
     179        foreach ($urls_before as $key => $url) {
     180            $this->assertEquals($urls_expected[$key], make_clickable($url));
     181        }
     182    }
     183
     184    // Based on a real comments which were incorrectly linked. #11211
    189185    function test_real_world_examples() {
    190         $this->knownWPBug(11211);
    191186        $urls_before = array(
    192187            'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant',
     
    204199    }
    205200
     201    // #14993
    206202    function test_twitter_hash_bang() {
    207         $this->knownWPBug(14993);
    208203        $urls_before = array(
    209204            'http://twitter.com/#!/wordpress/status/25907440233',
     
    220215        }
    221216    }
    222    
     217
    223218    function test_dont_break_attributes() {
    224219        $urls_before = array(
     
    246241class TestJSEscape extends WPTestCase {
    247242    function test_js_escape_simple() {
    248         $out = js_escape('foo bar baz();');
     243        $out = esc_js('foo bar baz();');
    249244        $this->assertEquals('foo bar baz();', $out);
    250245    }
    251    
     246
    252247    function test_js_escape_quotes() {
    253         $out = js_escape('foo "bar" \'baz\'');
     248        $out = esc_js('foo "bar" \'baz\'');
    254249        // does it make any sense to change " into &quot;?  Why not \"?
    255250        $this->assertEquals("foo &quot;bar&quot; \'baz\'", $out);
    256251    }
    257    
     252
    258253    function test_js_escape_backslash() {
    259254        $bs = '\\';
    260         $out = js_escape('foo '.$bs.'t bar '.$bs.$bs.' baz');
     255        $out = esc_js('foo '.$bs.'t bar '.$bs.$bs.' baz');
    261256        // \t becomes t - bug?
    262257        $this->assertEquals('foo t bar '.$bs.$bs.' baz', $out);
    263258    }
    264    
     259
    265260    function test_js_escape_amp() {
    266         $out = js_escape('foo & bar &baz;');
    267         $this->assertEquals("foo &#038; bar &baz;", $out);
    268     }
    269    
     261        $out = esc_js('foo & bar &baz; &apos;');
     262        $this->assertEquals("foo &amp; bar &amp;baz; &apos;", $out);
     263    }
     264
    270265    function test_js_escape_quote_entity() {
    271         $out = js_escape('foo &#x27; bar &#39; baz &#x26;');
    272         $this->assertEquals("foo \\' bar \\' baz &#x26;", $out);
     266        $out = esc_js('foo &#x27; bar &#39; baz &#x26;');
     267        $this->assertEquals("foo \\' bar \\' baz &amp;", $out);
    273268    }
    274269
    275270    function test_js_no_carriage_return() {
    276         $out = js_escape("foo\rbar\nbaz\r");
     271        $out = esc_js("foo\rbar\nbaz\r");
    277272        // \r is stripped
    278273        $this->assertequals("foobar\\nbaz", $out);
     
    280275
    281276    function test_js_escape_rn() {
    282         $out = js_escape("foo\r\nbar\nbaz\r\n");
     277        $out = esc_js("foo\r\nbar\nbaz\r\n");
    283278        // \r is stripped
    284279        $this->assertequals("foo\\nbar\\nbaz\\n", $out);
     
    299294        $this->assertEquals("Baba &amp; Dyado", wp_html_excerpt("Baba &amp; Dyado", 100));
    300295    }
    301 
    302 }
    303 
     296}
     297
     298/* // @todo These tests need to be rewritten for sanitize_sql_orderby
    304299class TestSanitizeOrderby extends WPTestCase {
    305    
    306300    function test_empty() {
    307         if ( !is_callable('sanitize_orderby') )
    308             $this->markTestSkipped();
    309 
    310301        $cols = array('a' => 'a');
    311         $this->assertEquals( '', sanitize_orderby('', $cols) );
    312         $this->assertEquals( '', sanitize_orderby('  ', $cols) );
    313         $this->assertEquals( '', sanitize_orderby("\t", $cols) );
    314         $this->assertEquals( '', sanitize_orderby(null, $cols) );
    315         $this->assertEquals( '', sanitize_orderby(0, $cols) );
    316         $this->assertEquals( '', sanitize_orderby('+', $cols) );
    317         $this->assertEquals( '', sanitize_orderby('-', $cols) );
    318     }
    319    
     302        $this->assertEquals( '', sanitize_sql_orderby('', $cols) );
     303        $this->assertEquals( '', sanitize_sql_orderby('  ', $cols) );
     304        $this->assertEquals( '', sanitize_sql_orderby("\t", $cols) );
     305        $this->assertEquals( '', sanitize_sql_orderby(null, $cols) );
     306        $this->assertEquals( '', sanitize_sql_orderby(0, $cols) );
     307        $this->assertEquals( '', sanitize_sql_orderby('+', $cols) );
     308        $this->assertEquals( '', sanitize_sql_orderby('-', $cols) );
     309    }
     310
    320311    function test_unknown_column() {
    321         if ( !is_callable('sanitize_orderby') )
    322             $this->markTestSkipped();
    323 
    324312        $cols = array('name' => 'post_name', 'date' => 'post_date');
    325         $this->assertEquals( '', sanitize_orderby('unknown_column', $cols) );
    326         $this->assertEquals( '', sanitize_orderby('+unknown_column', $cols) );
    327         $this->assertEquals( '', sanitize_orderby('-unknown_column', $cols) );
    328         $this->assertEquals( '', sanitize_orderby('-unknown1,+unknown2,unknown3', $cols) );
    329         $this->assertEquals( 'post_name ASC', sanitize_orderby('name,unknown_column', $cols) );
    330         $this->assertEquals( '', sanitize_orderby('!@#$%^&*()_=~`\'",./', $cols) );
     313        $this->assertEquals( '', sanitize_sql_orderby('unknown_column', $cols) );
     314        $this->assertEquals( '', sanitize_sql_orderby('+unknown_column', $cols) );
     315        $this->assertEquals( '', sanitize_sql_orderby('-unknown_column', $cols) );
     316        $this->assertEquals( '', sanitize_sql_orderby('-unknown1,+unknown2,unknown3', $cols) );
     317        $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name,unknown_column', $cols) );
     318        $this->assertEquals( '', sanitize_sql_orderby('!@#$%^&*()_=~`\'",./', $cols) );
    331319    }
    332320
    333321    function test_valid() {
    334         if ( !is_callable('sanitize_orderby') )
    335             $this->markTestSkipped();
    336 
    337322        $cols = array('name' => 'post_name', 'date' => 'post_date', 'random' => 'rand()');
    338         $this->assertEquals( 'post_name ASC', sanitize_orderby('name', $cols) );
    339         $this->assertEquals( 'post_name ASC', sanitize_orderby('+name', $cols) );
    340         $this->assertEquals( 'post_name DESC', sanitize_orderby('-name', $cols) );
    341         $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby('date,name', $cols) );
    342         $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_orderby(' date , name ', $cols) );
    343         $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_orderby('-name,date', $cols) );
    344         $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_orderby('name ,+ date', $cols) );
    345         $this->assertEquals( 'rand() ASC', sanitize_orderby('random', $cols) );
    346     }
    347 
    348 }
     323        $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('name', $cols) );
     324        $this->assertEquals( 'post_name ASC', sanitize_sql_orderby('+name', $cols) );
     325        $this->assertEquals( 'post_name DESC', sanitize_sql_orderby('-name', $cols) );
     326        $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby('date,name', $cols) );
     327        $this->assertEquals( 'post_date ASC, post_name ASC', sanitize_sql_orderby(' date , name ', $cols) );
     328        $this->assertEquals( 'post_name DESC, post_date ASC', sanitize_sql_orderby('-name,date', $cols) );
     329        $this->assertEquals( 'post_name ASC, post_date ASC', sanitize_sql_orderby('name ,+ date', $cols) );
     330        $this->assertEquals( 'rand() ASC', sanitize_sql_orderby('random', $cols) );
     331    }
     332}
     333*/
    349334
    350335class TestWPTexturize extends WPTestCase {
    351    
    352336    function test_dashes() {
    353337        $this->assertEquals('Hey &#8212; boo?', wptexturize('Hey -- boo?'));
    354338        $this->assertEquals('<a href="http://xx--xx">Hey &#8212; boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>'));
    355339    }
    356    
     340
    357341    function test_disable() {
    358342        $this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>'));
    359343        $this->assertEquals('[a]a&#8211;b[code]---[/code]a&#8211;b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]'));
    360344        $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>'));
    361    
     345
    362346        $this->assertEquals('<code>---</code>', wptexturize('<code>---</code>'));
    363        
     347
    364348        $this->assertEquals('<code>href="baba"</code> &#8220;baba&#8221;', wptexturize('<code>href="baba"</code> "baba"'));
    365        
     349
    366350        $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 &gt; topmp3.txt</code>';
    367351        $this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code));
    368            
     352
    369353        $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>';
    370354        $this->assertEquals($double_nest, wptexturize($double_nest));
    371        
     355
    372356        $invalid_nest = '<pre></code>"baba"</pre>';
    373357        $this->assertEquals($invalid_nest, wptexturize($invalid_nest));
    374358
    375359    }
    376    
     360
    377361    //WP Ticket #1418
    378362    function test_bracketed_quotes_1418() {
     
    386370        $this->assertEquals('A dog (&#8220;Hubertus&#8221;) was sent out.', wptexturize('A dog ("Hubertus") was sent out.'));
    387371    }
    388    
     372
    389373    //WP Ticket #4539
    390374    function test_basic_quotes() {
     
    430414        $this->assertEquals('A test with a number, &#8220;like 62&#8221;, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
    431415    }
    432    
     416
    433417    //WP Ticket #4539
    434418    function test_quotes_before_s() {
     
    452436        $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
    453437    }
    454    
     438
    455439    function test_quotes_after_numbers() {
    456440        $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
    457441    }
    458    
    459     //WP Ticket #15241
     442
     443    //WP Ticket #15241 and #4539
    460444    function test_other_html() {
    461         $this->knownWPBug(15241);
     445        $this->knownWPBug(4539);
    462446        $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>"));
    463447        $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
    464448        $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
    465449    }
    466    
     450
    467451    function test_x() {
    468452        $this->assertEquals('14&#215;24', wptexturize("14x24"));
    469453    }
    470    
     454
    471455    function test_minutes_seconds() {
    472456        $this->assertEquals('9&#8242;', wptexturize('9\''));
     
    475459        $this->assertEquals('a 9&#8242; b', wptexturize('a 9\' b'));
    476460        $this->assertEquals('a 9&#8243; b', wptexturize("a 9\" b"));
    477        
     461
    478462        $this->assertEquals('&#8220;a 9&#8242; b&#8221;', wptexturize('"a 9\' b"'));
    479463        $this->assertEquals('&#8216;a 9&#8243; b&#8217;', wptexturize("'a 9\" b'"));
    480464    }
    481    
     465
     466    //WP Ticket #15241 and #4539
    482467    function test_entity_quote_cuddling() {
    483         $this->knownWPBug(15357);
     468        $this->knownWPBug(4539);
    484469        $this->assertEquals('&nbsp;&#8220;Testing&#8221;', wptexturize('&nbsp;"Testing"'));
    485470        $this->assertEquals('&#38;&#8220;Testing&#8221;', wptexturize('&#38;"Testing"'));
     
    489474class TestCleanUrl extends WPTestCase {
    490475    function test_spaces() {
    491         $this->assertEquals('http://example.com/MrWordPress', clean_url('http://example.com/Mr WordPress'));
    492         $this->assertEquals('http://example.com/Mr%20WordPress', clean_url('http://example.com/Mr%20WordPress'));
    493     }
    494    
     476        $this->assertEquals('http://example.com/MrWordPress', esc_url('http://example.com/Mr WordPress'));
     477        $this->assertEquals('http://example.com/Mr%20WordPress', esc_url('http://example.com/Mr%20WordPress'));
     478    }
     479
    495480    function test_bad_characters() {
    496         $this->assertEquals('http://example.com/watchthelinefeedgo', clean_url('http://example.com/watchthelinefeed%0Ago'));
    497         $this->assertEquals('http://example.com/watchthelinefeedgo', clean_url('http://example.com/watchthelinefeed%0ago'));
    498         $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0Dgo'));
    499         $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0dgo'));
     481        $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0Ago'));
     482        $this->assertEquals('http://example.com/watchthelinefeedgo', esc_url('http://example.com/watchthelinefeed%0ago'));
     483        $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0Dgo'));
     484        $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0dgo'));
    500485        //Nesting Checks
    501         $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0%0ddgo'));
    502         $this->assertEquals('http://example.com/watchthecarriagereturngo', clean_url('http://example.com/watchthecarriagereturn%0%0DDgo'));
    503         $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0DAD'));
    504         $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0ADA'));
    505         $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0DAd'));
    506         $this->assertEquals('http://example.com/', clean_url('http://example.com/%0%0%0ADa'));
     486        $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0ddgo'));
     487        $this->assertEquals('http://example.com/watchthecarriagereturngo', esc_url('http://example.com/watchthecarriagereturn%0%0DDgo'));
     488        $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAD'));
     489        $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADA'));
     490        $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0DAd'));
     491        $this->assertEquals('http://example.com/', esc_url('http://example.com/%0%0%0ADa'));
    507492    }
    508493
    509494    function test_relative() {
    510         $this->assertEquals('/example.php', clean_url('/example.php'));
    511         $this->assertEquals('example.php', clean_url('example.php'));
    512     }
    513    
     495        $this->assertEquals('/example.php', esc_url('/example.php'));
     496        $this->assertEquals('example.php', esc_url('example.php'));
     497    }
     498
    514499    function test_protocol() {
    515         $this->assertEquals('http://example.com', clean_url('http://example.com'));
    516         $this->assertEquals('', clean_url('nasty://example.com/'));
    517     }
    518    
     500        $this->assertEquals('http://example.com', esc_url('http://example.com'));
     501        $this->assertEquals('', esc_url('nasty://example.com/'));
     502    }
     503
    519504    function test_display_extras() {
    520         $this->assertEquals('http://example.com/&#039;quoted&#039;', clean_url('http://example.com/\'quoted\''));
    521         $this->assertEquals('http://example.com/\'quoted\'', clean_url('http://example.com/\'quoted\'',null,'notdisplay'));
    522     }
    523    
     505        $this->assertEquals('http://example.com/&#039;quoted&#039;', esc_url('http://example.com/\'quoted\''));
     506        $this->assertEquals('http://example.com/\'quoted\'', esc_url('http://example.com/\'quoted\'',null,'notdisplay'));
     507    }
     508
    524509    function test_non_ascii() {
    525         $this->assertEquals( 'http://example.org/баба', clean_url( 'http://example.org/баба' ) );
    526         $this->assertEquals( 'http://баба.org/баба', clean_url( 'http://баба.org/баба' ) );
    527         $this->assertEquals( 'http://müller.com/', clean_url( 'http://müller.com/' ) );
     510        $this->assertEquals( 'http://example.org/баба', esc_url( 'http://example.org/баба' ) );
     511        $this->assertEquals( 'http://баба.org/баба', esc_url( 'http://баба.org/баба' ) );
     512        $this->assertEquals( 'http://müller.com/', esc_url( 'http://müller.com/' ) );
    528513    }
    529514}
     
    601586            'howdy\\\\howdy\\%howdy\\_'
    602587        );
    603        
     588
    604589        foreach ($inputs as $key => $input) {
    605590            $this->assertEquals($expected[$key], like_escape($input));
    606591        }
    607592    }
    608 
    609593}
    610594
    611595class TestSanitizeTextField extends WPTestCase {
     596    // #11528
    612597    function test_sanitize_text_field() {
    613         $this->knownWPBug(11528);
    614598        $inputs = array(
    615599            'оРангутанг', //Ensure UTF8 text is safe the Р is D0 A0 and A0 is the non-breaking space.
     
    620604            'we  also  trim  extra  internal  whitespace',
    621605            'tabs   get removed too',
    622             'newlines are not welcome 
     606            'newlines are not welcome
    623607            here',
    624608            'We also %AB remove %ab octets',
     
    645629            'Nested octects',
    646630        );
    647        
     631
    648632        foreach ($inputs as $key => $input) {
    649633            $this->assertEquals($expected[$key], sanitize_text_field($input));
Note: See TracChangeset for help on using the changeset viewer.