Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (5 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/post/template.php

    r47122 r48937  
    2222        $output   = wp_link_pages( array( 'echo' => 0 ) );
    2323
    24         $this->assertEquals( $expected, $output );
     24        $this->assertSame( $expected, $output );
    2525
    2626        $before_after = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span> {$page2}2</a> {$page3}3</a>";
     
    3333        );
    3434
    35         $this->assertEquals( $before_after, $output );
     35        $this->assertSame( $before_after, $output );
    3636
    3737        $separator = " <span class=\"post-page-numbers current\" aria-current=\"page\">1</span>{$page2}2</a>{$page3}3</a>";
     
    4545        );
    4646
    47         $this->assertEquals( $separator, $output );
     47        $this->assertSame( $separator, $output );
    4848
    4949        $link   = " <span class=\"post-page-numbers current\" aria-current=\"page\"><em>1</em></span>{$page2}<em>2</em></a>{$page3}<em>3</em></a>";
     
    5959        );
    6060
    61         $this->assertEquals( $link, $output );
     61        $this->assertSame( $link, $output );
    6262
    6363        $next   = "{$page2}<em>Next page</em></a>";
     
    7474        );
    7575
    76         $this->assertEquals( $next, $output );
     76        $this->assertSame( $next, $output );
    7777
    7878        $GLOBALS['page'] = 2;
     
    9090        );
    9191
    92         $this->assertEquals( $next_prev, $output );
     92        $this->assertSame( $next_prev, $output );
    9393
    9494        $next_prev_link = "{$permalink}Woo page</a>{$page3}Hoo page</a>";
     
    105105        );
    106106
    107         $this->assertEquals( $next_prev_link, $output );
     107        $this->assertSame( $next_prev_link, $output );
    108108
    109109        $GLOBALS['page'] = 1;
     
    116116        );
    117117
    118         $this->assertEquals( $separator, $output );
     118        $this->assertSame( $separator, $output );
    119119
    120120        $pagelink = " <span class=\"post-page-numbers current\" aria-current=\"page\">Page 1</span> | {$page2}Page 2</a> | {$page3}Page 3</a>";
     
    129129        );
    130130
    131         $this->assertEquals( $pagelink, $output );
     131        $this->assertSame( $pagelink, $output );
    132132    }
    133133
     
    165165
    166166        $output = wp_dropdown_pages( array( 'echo' => 0 ) );
    167         $this->assertEqualsIgnoreEOL( $lineage, $output );
     167        $this->assertSameIgnoreEOL( $lineage, $output );
    168168
    169169        $depth = <<<DEPTH
     
    180180            )
    181181        );
    182         $this->assertEqualsIgnoreEOL( $depth, $output );
     182        $this->assertSameIgnoreEOL( $depth, $output );
    183183
    184184        $option_none = <<<NONE
     
    198198            )
    199199        );
    200         $this->assertEqualsIgnoreEOL( $option_none, $output );
     200        $this->assertSameIgnoreEOL( $option_none, $output );
    201201
    202202        $option_no_change = <<<NO
     
    218218            )
    219219        );
    220         $this->assertEqualsIgnoreEOL( $option_no_change, $output );
     220        $this->assertSameIgnoreEOL( $option_no_change, $output );
    221221    }
    222222
     
    354354        );
    355355
    356         $this->assertEquals( '', get_page_template_slug( $page_id ) );
     356        $this->assertSame( '', get_page_template_slug( $page_id ) );
    357357
    358358        update_post_meta( $page_id, '_wp_page_template', 'default' );
    359         $this->assertEquals( '', get_page_template_slug( $page_id ) );
     359        $this->assertSame( '', get_page_template_slug( $page_id ) );
    360360
    361361        update_post_meta( $page_id, '_wp_page_template', 'example.php' );
    362         $this->assertEquals( 'example.php', get_page_template_slug( $page_id ) );
     362        $this->assertSame( 'example.php', get_page_template_slug( $page_id ) );
    363363    }
    364364
     
    376376        $this->go_to( get_permalink( $page_id ) );
    377377
    378         $this->assertEquals( 'example.php', get_page_template_slug() );
     378        $this->assertSame( 'example.php', get_page_template_slug() );
    379379    }
    380380
     
    386386        $post_id = self::factory()->post->create();
    387387
    388         $this->assertEquals( '', get_page_template_slug( $post_id ) );
     388        $this->assertSame( '', get_page_template_slug( $post_id ) );
    389389
    390390        update_post_meta( $post_id, '_wp_page_template', 'default' );
    391391
    392         $this->assertEquals( '', get_page_template_slug( $post_id ) );
     392        $this->assertSame( '', get_page_template_slug( $post_id ) );
    393393
    394394        update_post_meta( $post_id, '_wp_page_template', 'example.php' );
    395         $this->assertEquals( 'example.php', get_page_template_slug( $post_id ) );
     395        $this->assertSame( 'example.php', get_page_template_slug( $post_id ) );
    396396    }
    397397
     
    406406        $this->go_to( get_permalink( $post_id ) );
    407407
    408         $this->assertEquals( 'example.php', get_page_template_slug() );
     408        $this->assertSame( 'example.php', get_page_template_slug() );
    409409    }
    410410
Note: See TracChangeset for help on using the changeset viewer.