Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years 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/WPTrimWords.php

    r47122 r48937  
    1717    function test_trims_to_55_by_default() {
    1818        $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit…';
    19         $this->assertEquals( $trimmed, wp_trim_words( $this->long_text ) );
     19        $this->assertSame( $trimmed, wp_trim_words( $this->long_text ) );
    2020    }
    2121
    2222    function test_trims_to_10() {
    2323        $trimmed = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius…';
    24         $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 10 ) );
     24        $this->assertSame( $trimmed, wp_trim_words( $this->long_text, 10 ) );
    2525    }
    2626
    2727    function test_trims_to_5_and_uses_custom_more() {
    2828        $trimmed = 'Lorem ipsum dolor sit amet,[...] Read on!';
    29         $this->assertEquals( $trimmed, wp_trim_words( $this->long_text, 5, '[...] Read on!' ) );
     29        $this->assertSame( $trimmed, wp_trim_words( $this->long_text, 5, '[...] Read on!' ) );
    3030    }
    3131
     
    3333        $text    = 'This text contains a <a href="http://wordpress.org"> link </a> to WordPress.org!';
    3434        $trimmed = 'This text contains a link&hellip;';
    35         $this->assertEquals( $trimmed, wp_trim_words( $text, 5 ) );
     35        $this->assertSame( $trimmed, wp_trim_words( $text, 5 ) );
    3636    }
    3737
     
    4343
    4444        $text = 'This text contains<script>alert(" Javascript");</script>. It should go.';
    45         $this->assertEquals( $trimmed, wp_trim_words( $text ) );
     45        $this->assertSame( $trimmed, wp_trim_words( $text ) );
    4646
    4747        $text = 'This text contains<style>#css { width:expression(alert("css")) }</style>. It should go.';
    48         $this->assertEquals( $trimmed, wp_trim_words( $text ) );
     48        $this->assertSame( $trimmed, wp_trim_words( $text ) );
    4949    }
    5050
    5151    function test_doesnt_trim_short_text() {
    5252        $text = 'This is some short text.';
    53         $this->assertEquals( $text, wp_trim_words( $text ) );
     53        $this->assertSame( $text, wp_trim_words( $text ) );
    5454    }
    5555
     
    6262        $actual   = wp_trim_words( $this->long_text, 20 );
    6363        restore_previous_locale();
    64         $this->assertEquals( $expected, $actual );
     64        $this->assertSame( $expected, $actual );
    6565    }
    6666
     
    7474        $actual   = wp_trim_words( $text, 19 );
    7575        restore_previous_locale();
    76         $this->assertEquals( $expected, $actual );
     76        $this->assertSame( $expected, $actual );
    7777    }
    7878
     
    8181     */
    8282    function test_works_with_non_numeric_num_words() {
    83         $this->assertEquals( '', wp_trim_words( $this->long_text, '', '' ) );
    84         $this->assertEquals( '', wp_trim_words( $this->long_text, 'abc', '' ) );
    85         $this->assertEquals( '', wp_trim_words( $this->long_text, null, '' ) );
    86         $this->assertEquals( 'Lorem ipsum dolor', wp_trim_words( $this->long_text, '3', '' ) );
     83        $this->assertSame( '', wp_trim_words( $this->long_text, '', '' ) );
     84        $this->assertSame( '', wp_trim_words( $this->long_text, 'abc', '' ) );
     85        $this->assertSame( '', wp_trim_words( $this->long_text, null, '' ) );
     86        $this->assertSame( 'Lorem ipsum dolor', wp_trim_words( $this->long_text, '3', '' ) );
    8787    }
    8888}
Note: See TracChangeset for help on using the changeset viewer.