Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (3 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/general/document-title.php

    r46586 r48937  
    8181        add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) );
    8282
    83         $this->assertEquals( 'A Wild Title', wp_get_document_title() );
     83        $this->assertSame( 'A Wild Title', wp_get_document_title() );
    8484    }
    8585
     
    102102
    103103        $this->go_to( '/' );
    104         $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
     104        $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    105105
    106106        update_option( 'show_on_front', 'posts' );
    107107
    108108        $this->go_to( '/' );
    109         $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
     109        $this->assertSame( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    110110    }
    111111
     
    130130        // Show page name on home page if it's not the front page.
    131131        $this->go_to( get_permalink( $blog_page_id ) );
    132         $this->assertEquals( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
     132        $this->assertSame( sprintf( 'blog-page – %s', $this->blog_name ), wp_get_document_title() );
    133133    }
    134134
     
    138138        add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) );
    139139
    140         $this->assertEquals( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
     140        $this->assertSame( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    141141    }
    142142
     
    155155        add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) );
    156156
    157         $this->assertEquals( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() );
     157        $this->assertSame( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() );
    158158    }
    159159
     
    169169        $this->go_to( '?cat=' . self::$category_id );
    170170
    171         $this->assertEquals( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() );
     171        $this->assertSame( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() );
    172172    }
    173173
     
    175175        $this->go_to( '?s=test_title' );
    176176
    177         $this->assertEquals( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() );
     177        $this->assertSame( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() );
    178178    }
    179179
     
    181181        $this->go_to( '?author=' . self::$author_id );
    182182
    183         $this->assertEquals( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() );
     183        $this->assertSame( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() );
    184184    }
    185185
     
    204204        $this->go_to( '?post_type=cpt' );
    205205
    206         $this->assertEquals( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() );
     206        $this->assertSame( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() );
    207207    }
    208208
     
    210210        $this->go_to( '?year=2015' );
    211211
    212         $this->assertEquals( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() );
     212        $this->assertSame( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() );
    213213    }
    214214
     
    216216        $this->go_to( '?monthnum=09' );
    217217
    218         $this->assertEquals( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() );
     218        $this->assertSame( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() );
    219219    }
    220220
     
    222222        $this->go_to( '?day=22' );
    223223
    224         $this->assertEquals( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() );
     224        $this->assertSame( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() );
    225225    }
    226226
     
    228228        $this->go_to( '?m=404' );
    229229
    230         $this->assertEquals( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() );
     230        $this->assertSame( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() );
    231231    }
    232232
     
    236236        add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
    237237
    238         $this->assertEquals( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() );
     238        $this->assertSame( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() );
    239239    }
    240240
     
    253253        add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) );
    254254
    255         $this->assertEquals( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() );
     255        $this->assertSame( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() );
    256256    }
    257257
     
    270270        add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) );
    271271
    272         $this->assertEquals( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
     272        $this->assertSame( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
    273273    }
    274274
Note: See TracChangeset for help on using the changeset viewer.