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/xmlrpc/wp/editPost.php

    r47122 r48937  
    99        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'username', 'password', 0, array() ) );
    1010        $this->assertIXRError( $result );
    11         $this->assertEquals( 403, $result->code );
     11        $this->assertSame( 403, $result->code );
    1212    }
    1313
     
    2828
    2929        $out = get_post( $post_id );
    30         $this->assertEquals( $new_title, $out->post_title );
     30        $this->assertSame( $new_title, $out->post_title );
    3131    }
    3232
     
    4848
    4949        $out = get_post( $post_id );
    50         $this->assertEquals( $new_title, $out->post_title );
     50        $this->assertSame( $new_title, $out->post_title );
    5151    }
    5252
     
    6666        $result    = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    6767        $this->assertIXRError( $result );
    68         $this->assertEquals( 401, $result->code );
    69 
    70         $out = get_post( $post_id );
    71         $this->assertEquals( $original_title, $out->post_title );
     68        $this->assertSame( 401, $result->code );
     69
     70        $out = get_post( $post_id );
     71        $this->assertSame( $original_title, $out->post_title );
    7272    }
    7373
     
    105105        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
    106106        $this->assertIXRError( $result );
    107         $this->assertEquals( 401, $result->code );
     107        $this->assertSame( 401, $result->code );
    108108
    109109        $out = get_post( $post_id );
     
    144144        $post_id = wp_insert_post( $post );
    145145
    146         $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
     146        $this->assertSame( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
    147147
    148148        // Create attachment.
     
    182182        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) );
    183183        $this->assertNotIXRError( $result );
    184         $this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
     184        $this->assertSame( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
    185185
    186186        // Use invalid ID.
     
    188188        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) );
    189189        $this->assertIXRError( $result );
    190         $this->assertEquals( 404, $result->code );
     190        $this->assertSame( 404, $result->code );
    191191
    192192        remove_theme_support( 'post-thumbnails' );
     
    227227
    228228        $out = get_post( $post_id );
    229         $this->assertEquals( $new_title, $out->post_title );
     229        $this->assertSame( $new_title, $out->post_title );
    230230
    231231        $edited_object = get_metadata_by_mid( 'post', $mid_edit );
    232         $this->assertEquals( '87654321', $edited_object->meta_value );
     232        $this->assertSame( '87654321', $edited_object->meta_value );
    233233        $this->assertFalse( get_metadata_by_mid( 'post', $mid_delete ) );
    234234
    235235        $created_object = get_post_meta( $post_id, 'custom_field_to_create', true );
    236         $this->assertEquals( $created_object, '12345678' );
     236        $this->assertSame( $created_object, '12345678' );
    237237    }
    238238
     
    288288
    289289        // Make sure the edit went through.
    290         $this->assertEquals( 'First edit', get_post( $post_id )->post_content );
     290        $this->assertSame( 'First edit', get_post( $post_id )->post_content );
    291291
    292292        // Modify it again. We think it was last modified yesterday, but we actually just modified it above.
     
    297297        $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) );
    298298        $this->assertIXRError( $result );
    299         $this->assertEquals( 409, $result->code );
     299        $this->assertSame( 409, $result->code );
    300300
    301301        // Make sure the edit did not go through.
    302         $this->assertEquals( 'First edit', get_post( $post_id )->post_content );
     302        $this->assertSame( 'First edit', get_post( $post_id )->post_content );
    303303    }
    304304
     
    321321
    322322        // Make sure that the post status is still inherit.
    323         $this->assertEquals( 'inherit', get_post( $post_id )->post_status );
     323        $this->assertSame( 'inherit', get_post( $post_id )->post_status );
    324324    }
    325325
     
    340340
    341341        // Make sure that the post status is still inherit.
    342         $this->assertEquals( 'draft', get_post( $post_id )->post_status );
     342        $this->assertSame( 'draft', get_post( $post_id )->post_status );
    343343    }
    344344
     
    368368        );
    369369        $this->assertNotIXRError( $result );
    370         $this->assertEquals( 'Updated', get_post( $post_id )->post_title );
     370        $this->assertSame( 'Updated', get_post( $post_id )->post_title );
    371371
    372372        $term_ids = wp_list_pluck( get_the_category( $post_id ), 'term_id' );
     
    395395        $result           = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
    396396        $this->assertNotIXRError( $result );
    397         $this->assertEquals( 'Updated', get_post( $post_id )->post_title );
     397        $this->assertSame( 'Updated', get_post( $post_id )->post_title );
    398398
    399399        $term_ids = wp_list_pluck( get_the_category( $post_id ), 'term_id' );
     
    437437
    438438        // Verify that the correct data is there.
    439         $this->assertEquals( $enclosure_string, get_post_meta( $post_id, 'enclosure', true ) );
     439        $this->assertSame( $enclosure_string, get_post_meta( $post_id, 'enclosure', true ) );
    440440
    441441        // Attempt to add the enclosure a second time.
     
    443443
    444444        // Verify that there is only a single value in the array and that a duplicate is not present.
    445         $this->assertEquals( 1, count( get_post_meta( $post_id, 'enclosure' ) ) );
     445        $this->assertSame( 1, count( get_post_meta( $post_id, 'enclosure' ) ) );
    446446
    447447        // For good measure, check that the expected value is in the array.
     
    452452
    453453        // Having added the new enclosure, 2 values are expected in the array.
    454         $this->assertEquals( 2, count( get_post_meta( $post_id, 'enclosure' ) ) );
     454        $this->assertSame( 2, count( get_post_meta( $post_id, 'enclosure' ) ) );
    455455
    456456        // Check that the new enclosure is in the enclosure meta.
     
    492492
    493493        $after = get_post( $post_id );
    494         $this->assertEquals( 'future', $after->post_status );
     494        $this->assertSame( 'future', $after->post_status );
    495495
    496496        $future_date_string = strftime( '%Y-%m-%d %H:%M:%S', $future_time );
    497         $this->assertEquals( $future_date_string, $after->post_date );
     497        $this->assertSame( $future_date_string, $after->post_date );
    498498    }
    499499
     
    512512
    513513        $before = get_post( $post_id );
    514         $this->assertEquals( '0000-00-00 00:00:00', $before->post_date_gmt );
     514        $this->assertSame( '0000-00-00 00:00:00', $before->post_date_gmt );
    515515
    516516        // Edit the post without specifying any dates.
     
    524524        // The published date should still be zero.
    525525        $after = get_post( $post_id );
    526         $this->assertEquals( '0000-00-00 00:00:00', $after->post_date_gmt );
     526        $this->assertSame( '0000-00-00 00:00:00', $after->post_date_gmt );
    527527    }
    528528}
Note: See TracChangeset for help on using the changeset viewer.