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

    r47600 r48937  
    6363        $expected = str_replace( "\r\n", "\n", $expected );
    6464
    65         $this->assertEquals( $expected, wpautop( $test_data ) );
     65        $this->assertSame( $expected, wpautop( $test_data ) );
    6666    }
    6767
     
    7878        // Not wrapped in <p> tags.
    7979        $str = "<pre>$code</pre>";
    80         $this->assertEquals( $str, trim( wpautop( $str ) ) );
     80        $this->assertSame( $str, trim( wpautop( $str ) ) );
    8181
    8282        // Text before/after is wrapped in <p> tags.
     
    8585        // Expected text after wpautop().
    8686        $expected = '<p>Look at this code</p>' . "\n<pre>" . $code . "</pre>\n" . '<p>Isn\'t that cool?</p>';
    87         $this->assertEquals( $expected, trim( wpautop( $str ) ) );
     87        $this->assertSame( $expected, trim( wpautop( $str ) ) );
    8888
    8989        // Make sure HTML breaks are maintained if manually inserted.
    9090        $str      = "Look at this code\n\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n\nCool, huh?";
    9191        $expected = "<p>Look at this code</p>\n<pre>Line1<br />Line2<br>Line3<br/>Line4\nActual Line 2\nActual Line 3</pre>\n<p>Cool, huh?</p>";
    92         $this->assertEquals( $expected, trim( wpautop( $str ) ) );
     92        $this->assertSame( $expected, trim( wpautop( $str ) ) );
    9393    }
    9494
     
    100100    public function test_skip_input_elements() {
    101101        $str = 'Username: <input type="text" id="username" name="username" /><br />Password: <input type="password" id="password1" name="password1" />';
    102         $this->assertEquals( "<p>$str</p>", trim( wpautop( $str ) ) );
     102        $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
    103103    }
    104104
     
    184184            '<p>Paragraph two.</p>';
    185185
    186         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
    187         $this->assertEquals( $expected, trim( wpautop( $content2 ) ) );
    188         $this->assertEquals( $shortcode_expected, trim( wpautop( $shortcode_content ) ) );
     186        $this->assertSame( $expected, trim( wpautop( $content ) ) );
     187        $this->assertSame( $expected, trim( wpautop( $content2 ) ) );
     188        $this->assertSame( $shortcode_expected, trim( wpautop( $shortcode_content ) ) );
    189189    }
    190190
     
    264264            '<p>Paragraph two.</p>';
    265265
    266         $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) );
    267         $this->assertEquals( $expected2, trim( wpautop( $content2 ) ) );
     266        $this->assertSame( $expected1, trim( wpautop( $content1 ) ) );
     267        $this->assertSame( $expected2, trim( wpautop( $content2 ) ) );
    268268    }
    269269
     
    275275    public function test_skip_select_option_elements() {
    276276        $str = 'Country: <select id="state" name="state"><option value="1">Alabama</option><option value="2">Alaska</option><option value="3">Arizona</option><option value="4">Arkansas</option><option value="5">California</option></select>';
    277         $this->assertEquals( "<p>$str</p>", trim( wpautop( $str ) ) );
     277        $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
    278278    }
    279279
     
    341341        $input    = join( "\n\n", $content ); // Whitespace difference.
    342342
    343         $this->assertEquals( $expected, trim( wpautop( $input ) ) );
     343        $this->assertSame( $expected, trim( wpautop( $input ) ) );
    344344
    345345        $input = join( '', $content ); // Whitespace difference.
    346346
    347         $this->assertEquals( $expected, trim( wpautop( $input ) ) );
     347        $this->assertSame( $expected, trim( wpautop( $input ) ) );
    348348
    349349        // Check whitespace addition.
     
    357357        $input    = join( '', $content );
    358358
    359         $this->assertEquals( $expected, trim( wpautop( $input ) ) );
     359        $this->assertSame( $expected, trim( wpautop( $input ) ) );
    360360
    361361        // Check whitespace addition with attributes.
     
    369369        $input    = join( '', $content );
    370370
    371         $this->assertEquals( $expected, trim( wpautop( $input ) ) );
     371        $this->assertSame( $expected, trim( wpautop( $input ) ) );
    372372    }
    373373
     
    381381        $expected = '<blockquote><p>foo</p></blockquote>';
    382382
    383         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     383        $this->assertSame( $expected, trim( wpautop( $content ) ) );
    384384    }
    385385
     
    430430        $expected = join( "\n", $expected );
    431431
    432         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     432        $this->assertSame( $expected, trim( wpautop( $content ) ) );
    433433    }
    434434
     
    440440     */
    441441    function test_element_sanity( $input, $output ) {
    442         return $this->assertEquals( $output, wpautop( $input ) );
     442        return $this->assertSame( $output, wpautop( $input ) );
    443443    }
    444444
     
    506506line 5</p>';
    507507
    508         $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
     508        $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    509509    }
    510510
     
    525525<p>line 2</p>';
    526526
    527         $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
     527        $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    528528    }
    529529
     
    536536        $expected = "<p>a</p>\n<div>b</div>";
    537537
    538         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     538        $this->assertSame( $expected, trim( wpautop( $content ) ) );
    539539    }
    540540
     
    559559<img src="example.jpg" /><figcaption>Caption</figcaption></figure>';
    560560
    561         $this->assertEquals( $expected1, trim( wpautop( $content1 ) ) );
    562         $this->assertEqualsIgnoreEOL( $expected2, trim( wpautop( $content2 ) ) );
     561        $this->assertSame( $expected1, trim( wpautop( $content1 ) ) );
     562        $this->assertSameIgnoreEOL( $expected2, trim( wpautop( $content2 ) ) );
    563563    }
    564564
     
    570570        $expected = "<p>paragraph1</p>\n<hr>\n<p>paragraph2</p>";
    571571
    572         $this->assertEquals( $expected, trim( wpautop( $content ) ) );
     572        $this->assertSame( $expected, trim( wpautop( $content ) ) );
    573573    }
    574574
     
    588588        $expected = '<p>' . $content . '</p>';
    589589
    590         $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
     590        $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    591591    }
    592592
     
    604604        $expected = '<p>' . $content . '</p>';
    605605
    606         $this->assertEqualsIgnoreEOL( $expected, trim( wpautop( $content ) ) );
     606        $this->assertSameIgnoreEOL( $expected, trim( wpautop( $content ) ) );
    607607    }
    608608}
Note: See TracChangeset for help on using the changeset viewer.