WordPress.org

Make WordPress Core

Changeset 330 in tests


Ignore:
Timestamp:
01/25/2011 10:15:08 AM (7 years ago)
Author:
duck_
Message:

Numerous formatting test fixes

  • Removed TEST_DATA define
  • Moved get_testdata into _WPFormattingTest
  • Obvious fixes to test failures
  • Do not use deprecated wpspecialchars
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/jacob/TestFormatting.php

    r225 r330  
    44From http://wordpress.svn.dragonu.net/unittest/wp-unittest/UnitTests/
    55*/
    6 
    7 define('TEST_DATA', DIR_TESTDATA.'/jacob/');
    8 
    9 
    10 
    11 
    12 
    13 
    14 
    156class _WPFormattingTest extends WPTestCase {
    16    
    177    function file_test($name, $callback) {
    18         $input = get_testdata($name . ".input.txt");
    19         $output = get_testdata($name . ".output.txt");
     8        $input = $this->get_testdata($name . ".input.txt");
     9        $output = $this->get_testdata($name . ".output.txt");
    2010        for ($i=0; $i<count($input); ++$i) {
    2111            $in = call_user_func($callback, $input[$i]);
     
    2313        }
    2414    }
    25    
    26 }
    27 
    28 /*
    29 Get test data from files, one test per line.
    30 Comments start with "###".
    31 */
    32 function get_testdata($name) {
    33     $data = file(TEST_DATA . $name);
    34     $odata = array();
    35     foreach ($data as $datum) {
    36         // comment
    37         $commentpos = strpos($datum, "###");
    38         if ($commentpos !== false) {
    39             $datum = trim(substr($datum, 0, $commentpos));
    40             if (!$datum)
    41                 continue;
    42         }
    43         $odata[] = $datum;
    44     }
    45     return $odata;
    46 }
    47 
     15
     16    /*
     17    Get test data from files, one test per line.
     18    Comments start with "###".
     19    */
     20    function get_testdata($name) {
     21        $data = file( DIR_TESTDATA.'/jacob/'.$name );
     22        $odata = array();
     23        foreach ($data as $datum) {
     24            // comment
     25            $commentpos = strpos($datum, "###");
     26            if ($commentpos !== false) {
     27                $datum = trim(substr($datum, 0, $commentpos));
     28                if (!$datum)
     29                    continue;
     30            }
     31            $odata[] = $datum;
     32        }
     33        return $odata;
     34    }
     35}
    4836
    4937
     
    8573    function test_returns_true_for_utf8_strings() {
    8674        // from http://www.i18nguy.com/unicode-example.html
    87         $utf8 = get_testdata('utf-8.txt');
     75        $utf8 = $this->get_testdata('utf-8.txt');
    8876        $this->assertTrue(count($utf8) > 3);
    8977        foreach ($utf8 as $string) {
     
    9280    }
    9381    function test_returns_false_for_non_utf8_strings() {
    94         $big5 = get_testdata('test_big5.txt');
     82        $big5 = $this->get_testdata('test_big5.txt');
    9583        $big5 = $big5[0];
    9684        $strings = array(
     
    11098        $source = "penn & teller & at&t";
    11199        $res = "penn &amp; teller &amp; at&amp;t";
    112         $this->assertEquals($res, wp_specialchars($source));
     100        $this->assertEquals( $res, esc_html($source) );
    113101    }
    114102    function test_escapes_greater_and_less_than() {
    115103        $source = "this > that < that <randomhtml />";
    116104        $res = "this &gt; that &lt; that &lt;randomhtml /&gt;";
    117         $this->assertEquals($res, wp_specialchars($source));
     105        $this->assertEquals( $res, esc_html($source) );
    118106    }
    119107    function test_optionally_escapes_quotes() {
    120108        $source = "\"'hello!'\"";
    121         $this->assertEquals('"&#039;hello!&#039;"', wp_specialchars($source, 'single'));
    122         $this->assertEquals("&quot;'hello!'&quot;", wp_specialchars($source, 'double'));
    123         $this->assertEquals('&quot;&#039;hello!&#039;&quot;', wp_specialchars($source, true));
    124         $this->assertEquals($source, wp_specialchars($source));
     109        $this->assertEquals( '"&#039;hello!&#039;"', _wp_specialchars($source, 'single') );
     110        $this->assertEquals( "&quot;'hello!'&quot;", _wp_specialchars($source, 'double') );
     111        $this->assertEquals( '&quot;&#039;hello!&#039;&quot;', _wp_specialchars($source, true) );
     112        $this->assertEquals( $source, _wp_specialchars($source) );
    125113    }
    126114    function test_ignores_existing_entities() {
    127         $source = '&#038; &#x00A3; &#022; &amp;';
    128         $res = '&amp; &#x00A3; &#022; &amp;';
    129         $this->assertEquals($res, wp_specialchars($source));
     115        $source = '&#038; &#x00A3; &#x22; &amp;';
     116        $res = '&amp; &#xA3; &quot; &amp;';
     117        $this->assertEquals( $res, esc_html($source) );
    130118    }
    131119}
     
    137125    */
    138126    function test_percent_encodes_non_reserved_characters() {
    139         $utf8urls = get_testdata('utf-8.txt');
    140         $urlencoded = get_testdata('utf-8-urlencoded.txt');
     127        $utf8urls = $this->get_testdata('utf-8.txt');
     128        $urlencoded = $this->get_testdata('utf-8-urlencoded.txt');
    141129        for ($i=0; $i<count($utf8urls); ++$i) {
    142130            $this->assertEquals($urlencoded[$i], utf8_uri_encode($utf8urls[$i]));
     
    144132    }
    145133    function test_output_is_not_longer_than_optional_length_argument() {
    146         $utf8urls = get_testdata('utf-8.txt');
     134        $utf8urls = $this->get_testdata('utf-8.txt');
    147135        foreach ($utf8urls as $url) {
    148136            $maxlen = rand(5, 200);
     
    253241    }
    254242    function test_optional_strict_mode_reduces_to_safe_ascii_subset() {
    255         $this->assertEquals("abc", sanitize_user("()~ab~öcö!", true));
     243        $this->assertEquals("aboco", sanitize_user("()~ab~öcö!", true));
    256244    }
    257245}
     
    260248    function test_strips_html() {
    261249        $input = "Captain <strong>Awesome</strong>";
    262         $expected = "Captain Awesome";
     250        $expected = "captain-awesome";
    263251        $this->assertEquals($expected, sanitize_title($input));
    264252    }
     
    274262    function test_strips_html() {
    275263        $input = "Captain <strong>Awesome</strong>";
    276         $expected = "Captain Awesome";
     264        $expected = "captain-awesome";
    277265        $this->assertEquals($expected, sanitize_title($input));
    278266    }
     
    294282    }
    295283    function test_handles_non_entity_ampersands() {
    296         $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller; bull"));
     284        $this->assertEquals("penn-teller-bull", sanitize_title_with_dashes("penn & teller bull"));
    297285    }
    298286}
     
    332320        $prev = array($is_macIE, $is_winIE);
    333321        $is_macIE = $is_winIE = false;
    334         $data = get_testdata("utf-8-u-urlencoded.txt");
     322        $data = $this->get_testdata("utf-8-u-urlencoded.txt");
    335323        foreach ($data as $datum) {
    336324            $this->assertEquals($datum, funky_javascript_fix($datum));
     
    354342    }
    355343    function _run() {
    356         $input = get_testdata("utf-8-u-urlencoded.txt");
    357         $output = get_testdata("utf-8-entitized.txt");
     344        $input = $this->get_testdata("utf-8-u-urlencoded.txt");
     345        $output = $this->get_testdata("utf-8-entitized.txt");
    358346        for ($i=0; $i<count($input); ++$i) {
    359347            $this->assertEquals($output[$i], funky_javascript_fix($input[$i]));
     
    415403            "kevin@many.subdomains.make.a.happy.man.edu"
    416404            );
    417         foreach ($data as $datum) {
    418             $this->assertTrue(is_email($datum), $datum);
     405        foreach ( $data as $datum ) {
     406            $this->assertEquals( $datum, is_email($datum), $datum );
    419407        }
    420408    }
     
    447435class Test_Ent2NCR extends _WPFormattingTest {
    448436    function test_converts_named_entities_to_numeric_character_references() {
    449         $data = get_testdata("entities.txt");
     437        $data = $this->get_testdata("entities.txt");
    450438        foreach ($data as $datum) {
    451439            $parts = explode("|", $datum);
Note: See TracChangeset for help on using the changeset viewer.