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

    r47122 r48937  
    2222
    2323        remove_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) );
    24         $this->assertEquals( $paged, home_url( '/WooHoo/page/2/' ) );
     24        $this->assertSame( $paged, home_url( '/WooHoo/page/2/' ) );
    2525
    2626        $_SERVER['REQUEST_URI'] = $old_req_uri;
     
    3232
    3333        // Basic case.
    34         $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     34        $this->assertSame( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    3535
    3636        unset( $GLOBALS['post'] );
    3737
    3838        // Global post is not set.
    39         $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) );
    40         $this->assertEquals( '', wp_get_shortlink( 0 ) );
    41         $this->assertEquals( '', wp_get_shortlink() );
     39        $this->assertSame( '', wp_get_shortlink( 0, 'post' ) );
     40        $this->assertSame( '', wp_get_shortlink( 0 ) );
     41        $this->assertSame( '', wp_get_shortlink() );
    4242
    4343        $GLOBALS['post'] = get_post( $post_id );
    4444
    4545        // Global post is set.
    46         $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) );
    47         $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) );
    48         $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() );
     46        $this->assertSame( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) );
     47        $this->assertSame( get_permalink( $post_id ), wp_get_shortlink( 0 ) );
     48        $this->assertSame( get_permalink( $post_id ), wp_get_shortlink() );
    4949
    5050        // Not the global post.
    51         $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) );
     51        $this->assertSame( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) );
    5252
    5353        unset( $GLOBALS['post'] );
    5454
    5555        // Global post is not set, once again.
    56         $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) );
    57         $this->assertEquals( '', wp_get_shortlink( 0 ) );
    58         $this->assertEquals( '', wp_get_shortlink() );
     56        $this->assertSame( '', wp_get_shortlink( 0, 'post' ) );
     57        $this->assertSame( '', wp_get_shortlink( 0 ) );
     58        $this->assertSame( '', wp_get_shortlink() );
    5959
    6060        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     
    6262        // With a permalink structure set, get_permalink() will no longer match.
    6363        $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    64         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     64        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    6565
    6666        // Global post and permalink structure are set.
    6767        $GLOBALS['post'] = get_post( $post_id );
    68         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) );
    69         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
    70         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
     68        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) );
     69        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
     70        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink() );
    7171    }
    7272
     
    7676        // Basic case.
    7777        // Don't test against get_permalink() since it uses ?page_id= for pages.
    78         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    79 
    80         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    81 
    82         $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     78        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     79
     80        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     81
     82        $this->assertSame( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    8383    }
    8484
     
    9191        update_option( 'page_on_front', $post_id );
    9292
    93         $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
    94 
    95         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    96 
    97         $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
     93        $this->assertSame( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
     94
     95        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     96
     97        $this->assertSame( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
    9898    }
    9999
     
    115115        $non_pretty_permalink = add_query_arg( 'p', $p, trailingslashit( home_url() ) );
    116116
    117         $this->assertEquals( $non_pretty_permalink, get_permalink( $p ) );
     117        $this->assertSame( $non_pretty_permalink, get_permalink( $p ) );
    118118    }
    119119
     
    144144        );
    145145
    146         $this->assertEquals( $non_pretty_permalink, get_permalink( $p ) );
     146        $this->assertSame( $non_pretty_permalink, get_permalink( $p ) );
    147147    }
    148148
Note: See TracChangeset for help on using the changeset viewer.