WordPress.org

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/customize/custom-css-setting.php

    r48858 r48937  
    8080    function test_construct() {
    8181        $this->assertTrue( post_type_exists( 'custom_css' ) );
    82         $this->assertEquals( 'custom_css', $this->setting->type );
    83         $this->assertEquals( get_stylesheet(), $this->setting->stylesheet );
    84         $this->assertEquals( 'edit_css', $this->setting->capability );
     82        $this->assertSame( 'custom_css', $this->setting->type );
     83        $this->assertSame( get_stylesheet(), $this->setting->stylesheet );
     84        $this->assertSame( 'edit_css', $this->setting->capability );
    8585
    8686        $exception = null;
     
    114114
    115115        $this->setting->default = '/* Hello World */';
    116         $this->assertEquals( $this->setting->default, $this->setting->value() );
     116        $this->assertSame( $this->setting->default, $this->setting->value() );
    117117
    118118        $this->assertNull( wp_get_custom_css_post() );
     
    144144        remove_theme_mod( 'custom_css_post_id' );
    145145
    146         $this->assertEquals( $post_id, wp_get_custom_css_post()->ID );
    147         $this->assertEquals( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID );
    148         $this->assertEquals( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID );
    149 
    150         $this->assertEquals( $original_css, wp_get_custom_css( $this->setting->stylesheet ) );
    151         $this->assertEquals( $original_css, $this->setting->value() );
    152         $this->assertEquals( $twentyten_css, wp_get_custom_css( 'twentyten' ) );
    153         $this->assertEquals( $twentyten_css, $twentyten_setting->value() );
     146        $this->assertSame( $post_id, wp_get_custom_css_post()->ID );
     147        $this->assertSame( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID );
     148        $this->assertSame( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID );
     149
     150        $this->assertSame( $original_css, wp_get_custom_css( $this->setting->stylesheet ) );
     151        $this->assertSame( $original_css, $this->setting->value() );
     152        $this->assertSame( $twentyten_css, wp_get_custom_css( 'twentyten' ) );
     153        $this->assertSame( $twentyten_css, $twentyten_setting->value() );
    154154
    155155        $updated_css = 'body { color: blue; }';
     
    158158
    159159        $this->assertNotFalse( $saved );
    160         $this->assertEquals( $updated_css, $this->setting->value() );
    161         $this->assertEquals( $updated_css, wp_get_custom_css( $this->setting->stylesheet ) );
    162         $this->assertEquals( $updated_css, get_post( $post_id )->post_content );
     160        $this->assertSame( $updated_css, $this->setting->value() );
     161        $this->assertSame( $updated_css, wp_get_custom_css( $this->setting->stylesheet ) );
     162        $this->assertSame( $updated_css, get_post( $post_id )->post_content );
    163163
    164164        $previewed_css = 'body { color: red; }';
    165165        $this->wp_customize->set_post_value( $this->setting->id, $previewed_css );
    166166        $this->setting->preview();
    167         $this->assertEquals( $previewed_css, $this->setting->value() );
    168         $this->assertEquals( $previewed_css, wp_get_custom_css( $this->setting->stylesheet ) );
     167        $this->assertSame( $previewed_css, $this->setting->value() );
     168        $this->assertSame( $previewed_css, wp_get_custom_css( $this->setting->stylesheet ) );
    169169
    170170        // Make sure that wp_update_custom_css_post() works as expected for updates.
     
    177177        );
    178178        $this->assertInstanceOf( 'WP_Post', $r );
    179         $this->assertEquals( $post_id, $r->ID );
    180         $this->assertEquals( 'body { color:red; }', get_post( $r )->post_content );
    181         $this->assertEquals( "body\n\tcolor:red;", get_post( $r )->post_content_filtered );
     179        $this->assertSame( $post_id, $r->ID );
     180        $this->assertSame( 'body { color:red; }', get_post( $r )->post_content );
     181        $this->assertSame( "body\n\tcolor:red;", get_post( $r )->post_content_filtered );
    182182        $r = wp_update_custom_css_post( 'body { content: "\o/"; }' );
    183         $this->assertEquals( $this->wp_customize->get_stylesheet(), get_post( $r )->post_name );
    184         $this->assertEquals( 'body { content: "\o/"; }', get_post( $r )->post_content );
    185         $this->assertEquals( '', get_post( $r )->post_content_filtered );
     183        $this->assertSame( $this->wp_customize->get_stylesheet(), get_post( $r )->post_name );
     184        $this->assertSame( 'body { content: "\o/"; }', get_post( $r )->post_content );
     185        $this->assertSame( '', get_post( $r )->post_content_filtered );
    186186
    187187        // Make sure that wp_update_custom_css_post() works as expected for insertion.
     
    193193        );
    194194        $this->assertInstanceOf( 'WP_Post', $r );
    195         $this->assertEquals( 'other', get_post( $r )->post_name );
    196         $this->assertEquals( 'body { background:black; }', get_post( $r )->post_content );
    197         $this->assertEquals( 'publish', get_post( $r )->post_status );
     195        $this->assertSame( 'other', get_post( $r )->post_name );
     196        $this->assertSame( 'body { background:black; }', get_post( $r )->post_content );
     197        $this->assertSame( 'publish', get_post( $r )->post_status );
    198198
    199199        // Test deletion.
     
    201201        $this->assertNull( wp_get_custom_css_post() );
    202202        $this->assertNull( wp_get_custom_css_post( get_stylesheet() ) );
    203         $this->assertEquals( $previewed_css, wp_get_custom_css( get_stylesheet() ), 'Previewed value remains in spite of deleted post.' );
     203        $this->assertSame( $previewed_css, wp_get_custom_css( get_stylesheet() ), 'Previewed value remains in spite of deleted post.' );
    204204        wp_delete_post( $twentyten_post_id );
    205205        $this->assertNull( wp_get_custom_css_post( 'twentyten' ) );
    206         $this->assertEquals( '', wp_get_custom_css( 'twentyten' ) );
     206        $this->assertSame( '', wp_get_custom_css( 'twentyten' ) );
    207207    }
    208208
     
    272272        add_filter( 'customize_value_custom_css', array( $this, 'filter_value' ), 10, 2 );
    273273        $this->setting->default = '/*default*/';
    274         $this->assertEquals( '/*default*//*filtered*/', $this->setting->value() );
     274        $this->assertSame( '/*default*//*filtered*/', $this->setting->value() );
    275275
    276276        $this->factory()->post->create(
     
    284284        );
    285285        remove_theme_mod( 'custom_css_post_id' );
    286         $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() );
     286        $this->assertSame( '/*custom*//*filtered*/', $this->setting->value() );
    287287
    288288        $this->wp_customize->set_post_value( $this->setting->id, '/*overridden*/' );
    289289        $this->setting->preview();
    290         $this->assertEquals( '/*overridden*/', $this->setting->value(), 'Expected value to not be filtered since post value is present.' );
     290        $this->assertSame( '/*overridden*/', $this->setting->value(), 'Expected value to not be filtered since post value is present.' );
    291291    }
    292292
     
    331331
    332332        $post = get_post( $post_id );
    333         $this->assertEquals( $original_title, $post->post_title );
     333        $this->assertSame( $original_title, $post->post_title );
    334334        $this->assertContains( $overridden_css, $post->post_content );
    335335        $this->assertContains( '/* filtered post_content */', $post->post_content );
     
    347347        $this->assertInternalType( 'array', $data );
    348348        $this->assertEqualSets( array( 'css', 'preprocessed' ), array_keys( $data ) );
    349         $this->assertEquals( '', $data['preprocessed'] );
     349        $this->assertSame( '', $data['preprocessed'] );
    350350        $this->assertInternalType( 'array', $args );
    351351        $this->assertEqualSets( array( 'css', 'preprocessed', 'stylesheet' ), array_keys( $args ) );
    352         $this->assertEquals( $args['css'], $data['css'] );
    353         $this->assertEquals( $args['preprocessed'], $data['preprocessed'] );
     352        $this->assertSame( $args['css'], $data['css'] );
     353        $this->assertSame( $args['preprocessed'], $data['preprocessed'] );
    354354
    355355        $data['css']         .= '/* filtered post_content */';
Note: See TracChangeset for help on using the changeset viewer.