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

    r47122 r48937  
    88        // Simple string.
    99        $html = 'The quick brown fox.';
    10         $this->assertEquals( $html, esc_html( $html ) );
     10        $this->assertSame( $html, esc_html( $html ) );
    1111
    1212        // URL with &.
    1313        $html    = 'http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985';
    1414        $escaped = 'http://localhost/trunk/wp-login.php?action=logout&_wpnonce=cd57d75985';
    15         $this->assertEquals( $escaped, esc_html( $html ) );
     15        $this->assertSame( $escaped, esc_html( $html ) );
    1616
    1717        // SQL query.
    1818        $html    = "SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1";
    1919        $escaped = 'SELECT meta_key, meta_value FROM wp_trunk_sitemeta WHERE meta_key IN ('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled') AND site_id = 1';
    20         $this->assertEquals( $escaped, esc_html( $html ) );
     20        $this->assertSame( $escaped, esc_html( $html ) );
    2121    }
    2222
     
    2424        $source = 'penn & teller & at&t';
    2525        $res    = 'penn & teller & at&t';
    26         $this->assertEquals( $res, esc_html( $source ) );
     26        $this->assertSame( $res, esc_html( $source ) );
    2727    }
    2828
     
    3030        $source = 'this > that < that <randomhtml />';
    3131        $res    = 'this &gt; that &lt; that &lt;randomhtml /&gt;';
    32         $this->assertEquals( $res, esc_html( $source ) );
     32        $this->assertSame( $res, esc_html( $source ) );
    3333    }
    3434
     
    3636        $source = '&#038; &#x00A3; &#x22; &amp;';
    3737        $res    = '&#038; &#xA3; &#x22; &amp;';
    38         $this->assertEquals( $res, esc_html( $source ) );
     38        $this->assertSame( $res, esc_html( $source ) );
    3939    }
    4040}
Note: See TracChangeset for help on using the changeset viewer.