WordPress.org

Make WordPress Core

Changeset 427 in tests


Ignore:
Timestamp:
08/23/2011 03:45:50 PM (7 years ago)
Author:
nacin
Message:

Spaces to tabs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_formatting.php

    r426 r427  
    688688    }
    689689
    690     function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    691         $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
    692     }
    693 
    694     function test_trims_trailing_hyphens() {
    695         $this->assertEquals("a-t-t", sanitize_file_name("a----t----t----"));
    696     }
    697 
    698     function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
    699         $this->assertEquals("a-t", sanitize_file_name("a          t"));
    700         $this->assertEquals("a-t", sanitize_file_name("a    \n\n\nt"));
    701     }
     690    function test_replaces_any_number_of_hyphens_with_one_hyphen() {
     691        $this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
     692    }
     693
     694    function test_trims_trailing_hyphens() {
     695        $this->assertEquals("a-t-t", sanitize_file_name("a----t----t----"));
     696    }
     697
     698    function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
     699        $this->assertEquals("a-t", sanitize_file_name("a          t"));
     700        $this->assertEquals("a-t", sanitize_file_name("a    \n\n\nt"));
     701    }
    702702}
    703703
     
    731731    }
    732732
    733     function test_optionally_escapes_quotes() {
    734         $source = "\"'hello!'\"";
    735         $this->assertEquals( '"'hello!'"', _wp_specialchars($source, 'single') );
    736         $this->assertEquals( ""'hello!'"", _wp_specialchars($source, 'double') );
    737         $this->assertEquals( '"'hello!'"', _wp_specialchars($source, true) );
    738         $this->assertEquals( $source, _wp_specialchars($source) );
    739     }
     733    function test_optionally_escapes_quotes() {
     734        $source = "\"'hello!'\"";
     735        $this->assertEquals( '"'hello!'"', _wp_specialchars($source, 'single') );
     736        $this->assertEquals( ""'hello!'"", _wp_specialchars($source, 'double') );
     737        $this->assertEquals( '"'hello!'"', _wp_specialchars($source, true) );
     738        $this->assertEquals( $source, _wp_specialchars($source) );
     739    }
    740740}
    741741
     
    785785    }
    786786
    787     function test_escapes_ampersands() {
    788         $source = "penn & teller & at&t";
    789         $res = "penn & teller & at&t";
    790         $this->assertEquals( $res, esc_html($source) );
    791     }
    792 
    793     function test_escapes_greater_and_less_than() {
    794         $source = "this > that < that <randomhtml />";
    795         $res = "this &gt; that &lt; that &lt;randomhtml /&gt;";
    796         $this->assertEquals( $res, esc_html($source) );
    797     }
    798 
    799     function test_ignores_existing_entities() {
    800         $source = '&#038; &#x00A3; &#x22; &amp;';
    801         $res = '&amp; &#xA3; &quot; &amp;';
    802         $this->assertEquals( $res, esc_html($source) );
    803     }
     787    function test_escapes_ampersands() {
     788        $source = "penn & teller & at&t";
     789        $res = "penn &amp; teller &amp; at&amp;t";
     790        $this->assertEquals( $res, esc_html($source) );
     791    }
     792
     793    function test_escapes_greater_and_less_than() {
     794        $source = "this > that < that <randomhtml />";
     795        $res = "this &gt; that &lt; that &lt;randomhtml /&gt;";
     796        $this->assertEquals( $res, esc_html($source) );
     797    }
     798
     799    function test_ignores_existing_entities() {
     800        $source = '&#038; &#x00A3; &#x22; &amp;';
     801        $res = '&amp; &#xA3; &quot; &amp;';
     802        $this->assertEquals( $res, esc_html($source) );
     803    }
    804804}
    805805
    806806class TestSanitizeUser extends WPTestCase {
    807     function test_strips_html() {
    808         $input = "Captain <strong>Awesome</strong>";
    809         $expected = "Captain Awesome";
    810         $this->assertEquals($expected, sanitize_user($input));
    811     }
    812     function test_strips_entities() {
    813         $this->assertEquals("ATT", sanitize_user("AT&amp;T"));
    814     }
    815     function test_strips_percent_encoded_octets() {
    816         $this->assertEquals("Franois", sanitize_user("Fran%c3%a7ois"));
    817     }
    818     function test_optional_strict_mode_reduces_to_safe_ascii_subset() {
    819         $this->assertEquals("abc", sanitize_user("()~ab~ˆcˆ!", true));
    820     }
     807    function test_strips_html() {
     808        $input = "Captain <strong>Awesome</strong>";
     809        $expected = "Captain Awesome";
     810        $this->assertEquals($expected, sanitize_user($input));
     811    }
     812    function test_strips_entities() {
     813        $this->assertEquals("ATT", sanitize_user("AT&amp;T"));
     814    }
     815    function test_strips_percent_encoded_octets() {
     816        $this->assertEquals("Franois", sanitize_user("Fran%c3%a7ois"));
     817    }
     818    function test_optional_strict_mode_reduces_to_safe_ascii_subset() {
     819        $this->assertEquals("abc", sanitize_user("()~ab~ˆcˆ!", true));
     820    }
    821821}
    822822
    823823class TestIsEmail extends WPTestCase {
    824     function test_returns_true_if_given_a_valid_email_address() {
    825         $data = array(
    826             "bob@example.com",
    827             "phil@example.info",
    828             "ace@204.32.222.14",
    829             "kevin@many.subdomains.make.a.happy.man.edu"
    830             );
    831         foreach ( $data as $datum ) {
    832             $this->assertEquals( $datum, is_email($datum), $datum );
    833         }
    834     }
    835 
    836     function test_returns_false_if_given_an_invalid_email_address() {
    837         $data = array(
    838             "khaaaaaaaaaaaaaaan!",
    839             'http://bob.example.com/',
    840             "sif i'd give u it, spamer!1",
    841             "com.exampleNOSPAMbob",
    842             "bob@your mom"
    843             );
    844         foreach ($data as $datum) {
    845             $this->assertFalse(is_email($datum), $datum);
    846         }
    847     }
     824    function test_returns_true_if_given_a_valid_email_address() {
     825        $data = array(
     826            "bob@example.com",
     827            "phil@example.info",
     828            "ace@204.32.222.14",
     829            "kevin@many.subdomains.make.a.happy.man.edu"
     830            );
     831        foreach ( $data as $datum ) {
     832            $this->assertEquals( $datum, is_email($datum), $datum );
     833        }
     834    }
     835
     836    function test_returns_false_if_given_an_invalid_email_address() {
     837        $data = array(
     838            "khaaaaaaaaaaaaaaan!",
     839            'http://bob.example.com/',
     840            "sif i'd give u it, spamer!1",
     841            "com.exampleNOSPAMbob",
     842            "bob@your mom"
     843            );
     844        foreach ($data as $datum) {
     845            $this->assertFalse(is_email($datum), $datum);
     846        }
     847    }
    848848}
    849849
    850850class TestSanitizeTitle extends WPTestCase {
    851     function test_strips_html() {
    852         $input = "Captain <strong>Awesome</strong>";
    853         $expected = "captain-awesome";
    854         $this->assertEquals($expected, sanitize_title($input));
    855     }
    856 
    857     function test_titles_sanitized_to_nothing_are_replaced_with_optional_fallback() {
    858         $input = "<strong></strong>";
    859         $fallback = "Captain Awesome";
    860         $this->assertEquals($fallback, sanitize_title($input, $fallback));
    861     }
     851    function test_strips_html() {
     852        $input = "Captain <strong>Awesome</strong>";
     853        $expected = "captain-awesome";
     854        $this->assertEquals($expected, sanitize_title($input));
     855    }
     856
     857    function test_titles_sanitized_to_nothing_are_replaced_with_optional_fallback() {
     858        $input = "<strong></strong>";
     859        $fallback = "Captain Awesome";
     860        $this->assertEquals($fallback, sanitize_title($input, $fallback));
     861    }
    862862}
    863863
    864864class TestSanitizeTitleWithDashes extends WPTestCase {
    865     function test_strips_html() {
    866         $input = "Captain <strong>Awesome</strong>";
    867         $expected = "captain-awesome";
    868         $this->assertEquals($expected, sanitize_title($input));
    869     }
    870 
    871     function test_strips_unencoded_percent_signs() {
    872         $this->assertEquals("fran%c3%a7ois", sanitize_title_with_dashes("fran%c3%a7%ois"));
    873     }
    874 
    875     function test_makes_title_lowercase() {
    876         $this->assertEquals("abc", sanitize_title_with_dashes("ABC"));
    877     }
    878 
    879     function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
    880         $this->assertEquals("a-t", sanitize_title_with_dashes("a          t"));
    881         $this->assertEquals("a-t", sanitize_title_with_dashes("a    \n\n\nt"));
    882     }
    883 
    884     function test_replaces_any_number_of_hyphens_with_one_hyphen() {
    885         $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t"));
    886     }
    887 
    888     function test_trims_trailing_hyphens() {
    889         $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));
    890     }
    891 
    892     function test_handles_non_entity_ampersands() {
    893         $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
    894     }
     865    function test_strips_html() {
     866        $input = "Captain <strong>Awesome</strong>";
     867        $expected = "captain-awesome";
     868        $this->assertEquals($expected, sanitize_title($input));
     869    }
     870
     871    function test_strips_unencoded_percent_signs() {
     872        $this->assertEquals("fran%c3%a7ois", sanitize_title_with_dashes("fran%c3%a7%ois"));
     873    }
     874
     875    function test_makes_title_lowercase() {
     876        $this->assertEquals("abc", sanitize_title_with_dashes("ABC"));
     877    }
     878
     879    function test_replaces_any_amount_of_whitespace_with_one_hyphen() {
     880        $this->assertEquals("a-t", sanitize_title_with_dashes("a          t"));
     881        $this->assertEquals("a-t", sanitize_title_with_dashes("a    \n\n\nt"));
     882    }
     883
     884    function test_replaces_any_number_of_hyphens_with_one_hyphen() {
     885        $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t"));
     886    }
     887
     888    function test_trims_trailing_hyphens() {
     889        $this->assertEquals("a-t-t", sanitize_title_with_dashes("a----t----t----"));
     890    }
     891
     892    function test_handles_non_entity_ampersands() {
     893        $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
     894    }
    895895}
    896896
    897897class TestConvertChars extends WPTestCase {
    898     function test_replaces_windows1252_entities_with_unicode_ones() {
    899         $input = "&#130;&#131;&#132;&#133;&#134;&#135;&#136;&#137;&#138;&#139;&#140;&#145;&#146;&#147;&#148;&#149;&#150;&#151;&#152;&#153;&#154;&#155;&#156;&#159;";
    900         $output = "&#8218;&#402;&#8222;&#8230;&#8224;&#8225;&#710;&#8240;&#352;&#8249;&#338;&#8216;&#8217;&#8220;&#8221;&#8226;&#8211;&#8212;&#732;&#8482;&#353;&#8250;&#339;&#376;";
    901         $this->assertEquals($output, convert_chars($input));
    902     }
    903 
    904     function test_converts_html_br_and_hr_to_the_xhtml_self_closing_variety() {
    905         $inputs = array(
    906             "abc <br> lol <br />" => "abc <br /> lol <br />",
    907             "<BR> HO HO <HR>"     => "<br /> ho ho <hr />",
    908             "<hr><br>"            => "<hr /><br />"
    909             );
    910         foreach ($inputs as $input => $expected) {
    911             $this->assertEquals($expected, convert_chars($input));
    912         }
    913     }
    914 
    915     function test_escapes_lone_ampersands() {
    916         $this->assertEquals("at&#038;t", convert_chars("at&t"));
    917     }
    918 
    919     function test_removes_category_and_title_metadata_tags() {
    920         $this->assertEquals("", convert_chars("<title><div class='lol'>abc</div></title><category>a</category>"));
    921     }
     898    function test_replaces_windows1252_entities_with_unicode_ones() {
     899        $input = "&#130;&#131;&#132;&#133;&#134;&#135;&#136;&#137;&#138;&#139;&#140;&#145;&#146;&#147;&#148;&#149;&#150;&#151;&#152;&#153;&#154;&#155;&#156;&#159;";
     900        $output = "&#8218;&#402;&#8222;&#8230;&#8224;&#8225;&#710;&#8240;&#352;&#8249;&#338;&#8216;&#8217;&#8220;&#8221;&#8226;&#8211;&#8212;&#732;&#8482;&#353;&#8250;&#339;&#376;";
     901        $this->assertEquals($output, convert_chars($input));
     902    }
     903
     904    function test_converts_html_br_and_hr_to_the_xhtml_self_closing_variety() {
     905        $inputs = array(
     906            "abc <br> lol <br />" => "abc <br /> lol <br />",
     907            "<BR> HO HO <HR>"     => "<br /> ho ho <hr />",
     908            "<hr><br>"            => "<hr /><br />"
     909            );
     910        foreach ($inputs as $input => $expected) {
     911            $this->assertEquals($expected, convert_chars($input));
     912        }
     913    }
     914
     915    function test_escapes_lone_ampersands() {
     916        $this->assertEquals("at&#038;t", convert_chars("at&t"));
     917    }
     918
     919    function test_removes_category_and_title_metadata_tags() {
     920        $this->assertEquals("", convert_chars("<title><div class='lol'>abc</div></title><category>a</category>"));
     921    }
    922922}
    923923
    924924class TestBalanceTags extends WPTestCase {
    925     function test_adds_missing_end_tags() {
    926         $this->assertEquals("<b><i>abc</i></b>", balanceTags("<b><i>abc</b>", true));
    927     }
    928 
    929     function test_fixes_simple_bad_nesting() {
    930         $this->assertEquals("<b><i>abc</i></b>", balanceTags("<b><i>abc</b></i>", true));
    931     }
     925    function test_adds_missing_end_tags() {
     926        $this->assertEquals("<b><i>abc</i></b>", balanceTags("<b><i>abc</b>", true));
     927    }
     928
     929    function test_fixes_simple_bad_nesting() {
     930        $this->assertEquals("<b><i>abc</i></b>", balanceTags("<b><i>abc</b></i>", true));
     931    }
    932932
    933933    function test_nestable_tags() {
     
    940940
    941941class TestZeroise extends WPTestCase {
    942     function test_pads_with_leading_zeroes() {
    943         $this->assertEquals("00005", zeroise(5, 5));
    944     }
    945 
    946     function test_does_nothing_if_input_is_already_longer() {
    947         $this->assertEquals("5000000", zeroise(5000000, 2));
    948     }
     942    function test_pads_with_leading_zeroes() {
     943        $this->assertEquals("00005", zeroise(5, 5));
     944    }
     945
     946    function test_does_nothing_if_input_is_already_longer() {
     947        $this->assertEquals("5000000", zeroise(5000000, 2));
     948    }
    949949}
    950950
    951951class TestBackslashit extends WPTestCase {
    952     function test_backslashes_alphas() {
    953         $this->assertEquals("\\a943\\b\\c", backslashit("a943bc"));
    954     }
    955 
    956     function test_double_backslashes_leading_numbers() {
    957         $this->assertEquals("\\\\95", backslashit("95"));
    958     }
     952    function test_backslashes_alphas() {
     953        $this->assertEquals("\\a943\\b\\c", backslashit("a943bc"));
     954    }
     955
     956    function test_double_backslashes_leading_numbers() {
     957        $this->assertEquals("\\\\95", backslashit("95"));
     958    }
    959959}
    960960
    961961class TestUntrailingslashit extends WPTestCase {
    962     function test_removes_trailing_slashes() {
    963         $this->assertEquals("a", untrailingslashit("a/"));
    964         $this->assertEquals("a", untrailingslashit("a////"));
    965     }
     962    function test_removes_trailing_slashes() {
     963        $this->assertEquals("a", untrailingslashit("a/"));
     964        $this->assertEquals("a", untrailingslashit("a////"));
     965    }
    966966}
    967967
    968968class TestTrailingslashit extends WPTestCase {
    969     function test_adds_trailing_slash() {
    970         $this->assertEquals("a/", trailingslashit("a"));
    971     }
    972 
    973     function test_does_not_add_trailing_slash_if_one_exists() {
    974         $this->assertEquals("a/", trailingslashit("a/"));
    975     }
     969    function test_adds_trailing_slash() {
     970        $this->assertEquals("a/", trailingslashit("a"));
     971    }
     972
     973    function test_does_not_add_trailing_slash_if_one_exists() {
     974        $this->assertEquals("a/", trailingslashit("a/"));
     975    }
    976976}
    977977
     
    979979   tags within `<pre>` elements as part of `wpautop`. */
    980980class TestCleanPre extends WPTestCase {
    981     function test_removes_self_closing_br_with_space() {
    982         $source = 'a b c\n<br />sldfj<br />';
    983         $res = 'a b c\nsldfj';
    984 
    985         $this->assertEquals($res, clean_pre($source));
    986     }
    987 
    988     function test_removes_self_closing_br_without_space() {
    989         $source = 'a b c\n<br/>sldfj<br/>';
    990         $res = 'a b c\nsldfj';
    991         $this->assertEquals($res, clean_pre($source));
    992     }
    993 
    994     // I don't think this can ever happen in production;
    995     // <br> is changed to <br /> elsewhere. Left in because
    996     // that replacement shouldn't happen (what if you want
    997     // HTML 4 output?).
    998     function test_removes_html_br() {
    999         $source = 'a b c\n<br>sldfj<br>';
    1000         $res = 'a b c\nsldfj';
    1001         $this->assertEquals($res, clean_pre($source));
    1002     }
    1003 
    1004     function test_removes_p() {
    1005         $source = "<p>isn't this exciting!</p><p>oh indeed!</p>";
    1006         $res = "\nisn't this exciting!\noh indeed!";
    1007         $this->assertEquals($res, clean_pre($source));
    1008     }
     981    function test_removes_self_closing_br_with_space() {
     982        $source = 'a b c\n<br />sldfj<br />';
     983        $res = 'a b c\nsldfj';
     984
     985        $this->assertEquals($res, clean_pre($source));
     986    }
     987
     988    function test_removes_self_closing_br_without_space() {
     989        $source = 'a b c\n<br/>sldfj<br/>';
     990        $res = 'a b c\nsldfj';
     991        $this->assertEquals($res, clean_pre($source));
     992    }
     993
     994    // I don't think this can ever happen in production;
     995    // <br> is changed to <br /> elsewhere. Left in because
     996    // that replacement shouldn't happen (what if you want
     997    // HTML 4 output?).
     998    function test_removes_html_br() {
     999        $source = 'a b c\n<br>sldfj<br>';
     1000        $res = 'a b c\nsldfj';
     1001        $this->assertEquals($res, clean_pre($source));
     1002    }
     1003
     1004    function test_removes_p() {
     1005        $source = "<p>isn't this exciting!</p><p>oh indeed!</p>";
     1006        $res = "\nisn't this exciting!\noh indeed!";
     1007        $this->assertEquals($res, clean_pre($source));
     1008    }
    10091009}
    10101010
Note: See TracChangeset for help on using the changeset viewer.