Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/MakeClickable.php

    r47122 r48937  
    77    function test_mailto_xss() {
    88        $in = 'testzzz@"STYLE="behavior:url(\'#default#time2\')"onBegin="alert(\'refresh-XSS\')"';
    9         $this->assertEquals( $in, make_clickable( $in ) );
     9        $this->assertSame( $in, make_clickable( $in ) );
    1010    }
    1111
     
    1919        );
    2020        foreach ( $valid_emails as $email ) {
    21             $this->assertEquals( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
     21            $this->assertSame( '<a href="mailto:' . $email . '">' . $email . '</a>', make_clickable( $email ) );
    2222        }
    2323    }
     
    3333        );
    3434        foreach ( $invalid_emails as $email ) {
    35             $this->assertEquals( $email, make_clickable( $email ) );
     35            $this->assertSame( $email, make_clickable( $email ) );
    3636        }
    3737    }
     
    6060
    6161        foreach ( $urls_before as $key => $url ) {
    62             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     62            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    6363        }
    6464    }
     
    8989
    9090        foreach ( $urls_before as $key => $url ) {
    91             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     91            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    9292        }
    9393    }
     
    116116
    117117        foreach ( $urls_before as $key => $url ) {
    118             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     118            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    119119        }
    120120    }
     
    143143
    144144        foreach ( $urls_before as $key => $url ) {
    145             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     145            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    146146        }
    147147    }
     
    162162        );
    163163        foreach ( $urls_before as $key => $url ) {
    164             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     164            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    165165        }
    166166    }
     
    199199        );
    200200        foreach ( $urls_before as $key => $url ) {
    201             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     201            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    202202        }
    203203    }
     
    222222        );
    223223        foreach ( $urls_before as $key => $url ) {
    224             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     224            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    225225        }
    226226    }
     
    241241        );
    242242        foreach ( $urls_before as $key => $url ) {
    243             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     243            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    244244        }
    245245    }
     
    257257        );
    258258        foreach ( $before as $key => $url ) {
    259             $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
     259            $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    260260        }
    261261    }
     
    279279        );
    280280        foreach ( $before as $key => $url ) {
    281             $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
     281            $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    282282        }
    283283    }
     
    303303        );
    304304        foreach ( $urls_before as $key => $url ) {
    305             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     305            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    306306        }
    307307    }
     
    344344
    345345        foreach ( $before as $key => $url ) {
    346             $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
     346            $this->assertSame( $expected[ $key ], make_clickable( $url ) );
    347347        }
    348348    }
     
    361361        );
    362362        foreach ( $urls_before as $key => $url ) {
    363             $this->assertEquals( $urls_expected[ $key ], make_clickable( $url ) );
     363            $this->assertSame( $urls_expected[ $key ], make_clickable( $url ) );
    364364        }
    365365    }
     
    371371        );
    372372        foreach ( $in as $text ) {
    373             $this->assertEquals( $text, make_clickable( $text ) );
     373            $this->assertSame( $text, make_clickable( $text ) );
    374374        }
    375375    }
     
    381381        $in  = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );
    382382        $out = make_clickable( $in );
    383         $this->assertEquals( $in, $out );
     383        $this->assertSame( $in, $out );
    384384    }
    385385
     
    390390        $html = "<a
    391391                  href='mailto:someone@example.com'>someone@example.com</a>";
    392         $this->assertEquals( $html, make_clickable( $html ) );
     392        $this->assertSame( $html, make_clickable( $html ) );
    393393    }
    394394
     
    398398     */
    399399    public function test_dont_link_script_and_style_tags( $tag ) {
    400         $this->assertEquals( $tag, make_clickable( $tag ) );
     400        $this->assertSame( $tag, make_clickable( $tag ) );
    401401    }
    402402
Note: See TracChangeset for help on using the changeset viewer.