WordPress.org

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/WPSpecialchars.php

    r47122 r48937  
    77    function test_wp_specialchars_basics() {
    88        $html = '&<hello world>';
    9         $this->assertEquals( $html, _wp_specialchars( $html ) );
     9        $this->assertSame( $html, _wp_specialchars( $html ) );
    1010
    1111        $double = '&<hello world>';
    12         $this->assertEquals( $double, _wp_specialchars( $html, ENT_NOQUOTES, false, true ) );
     12        $this->assertSame( $double, _wp_specialchars( $html, ENT_NOQUOTES, false, true ) );
    1313    }
    1414
     
    2323            }
    2424            $ent = '&' . $ent . ';';
    25             $this->assertEquals( $ent, _wp_specialchars( $ent ) );
     25            $this->assertSame( $ent, _wp_specialchars( $ent ) );
    2626        }
    2727    }
     
    3333            $escaped = '&' . $ent . ';';
    3434            $ent     = '&' . $ent . ';';
    35             $this->assertEquals( $escaped, _wp_specialchars( $ent ) );
     35            $this->assertSame( $escaped, _wp_specialchars( $ent ) );
    3636        }
    3737    }
     
    3939    function test_optionally_escapes_quotes() {
    4040        $source = "\"'hello!'\"";
    41         $this->assertEquals( '"'hello!'"', _wp_specialchars( $source, 'single' ) );
    42         $this->assertEquals( ""'hello!'"", _wp_specialchars( $source, 'double' ) );
    43         $this->assertEquals( '"'hello!'"', _wp_specialchars( $source, true ) );
    44         $this->assertEquals( $source, _wp_specialchars( $source ) );
     41        $this->assertSame( '"'hello!'"', _wp_specialchars( $source, 'single' ) );
     42        $this->assertSame( ""'hello!'"", _wp_specialchars( $source, 'double' ) );
     43        $this->assertSame( '"'hello!'"', _wp_specialchars( $source, true ) );
     44        $this->assertSame( $source, _wp_specialchars( $source ) );
    4545    }
    4646
     
    5252     */
    5353    function test_double_encoding( $input, $output ) {
    54         return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, true ) );
     54        return $this->assertSame( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, true ) );
    5555    }
    5656
     
    7979     */
    8080    function test_no_double_encoding( $input, $output ) {
    81         return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, false ) );
     81        return $this->assertSame( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, false ) );
    8282    }
    8383
Note: See TracChangeset for help on using the changeset viewer.