Make WordPress Core

Changeset 57744


Ignore:
Timestamp:
02/29/2024 08:00:07 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in post meta revisioning 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.

Includes correcting the test class name.

Follow-up to [56714].

See #59655.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/metaRevisions.php

    r56714 r57744  
    1010 * @group meta-revisions
    1111 */
    12 class MetaRevisionTests extends WP_UnitTestCase {
     12class Tests_Post_MetaRevisions extends WP_UnitTestCase {
    1313
    1414    /**
     
    5151        // Store a custom meta value, which is not revisioned by default.
    5252        update_post_meta( $post_id, 'meta_revision_test', wp_slash( $passed ) );
    53         $this->assertEquals( $expected, get_post_meta( $post_id, 'meta_revision_test', true ) );
     53        $this->assertSame( $expected, get_post_meta( $post_id, 'meta_revision_test', true ) );
    5454
    5555        // Update the post, storing a revision.
     
    8181        wp_restore_post_revision( $last_revision->ID );
    8282
    83         $this->assertEquals( $expected, get_post_meta( $post_id, 'meta_revision_test', true ) );
     83        $this->assertSame( $expected, get_post_meta( $post_id, 'meta_revision_test', true ) );
    8484    }
    8585
     
    189189
    190190        // Custom post meta should NOT be restored, orignal value should not be restored, value still 'update1'.
    191         $this->assertEquals( 'update1', get_post_meta( $post_id, 'meta_revision_test', true ) );
     191        $this->assertSame( 'update1', get_post_meta( $post_id, 'meta_revision_test', true ) );
    192192
    193193        update_post_meta( $post_id, 'meta_revision_test', 'update2' );
     
    210210        $revisions = array_values( wp_get_post_revisions( $post_id ) );
    211211        $this->assertCount( 5, $revisions );
    212         $this->assertEquals( 'update2', get_post_meta( $revisions[0]->ID, 'meta_revision_test', true ) );
     212        $this->assertSame( 'update2', get_post_meta( $revisions[0]->ID, 'meta_revision_test', true ) );
    213213
    214214        // Store custom meta values, which should now be revisioned.
     
    232232
    233233        // Verify that previous post meta is set.
    234         $this->assertEquals( 'update3', get_post_meta( $post_id, 'meta_revision_test', true ) );
     234        $this->assertSame( 'update3', get_post_meta( $post_id, 'meta_revision_test', true ) );
    235235
    236236        // Restore the previous revision.
     
    245245         * Verify that previous post meta is restored.
    246246         */
    247         $this->assertEquals( 'update2', get_post_meta( $post_id, 'meta_revision_test', true ) );
     247        $this->assertSame( 'update2', get_post_meta( $post_id, 'meta_revision_test', true ) );
    248248
    249249        // Try storing a blank meta.
     
    271271         * Verify that previous blank post meta is restored.
    272272         */
    273         $this->assertEquals( '', get_post_meta( $post_id, 'meta_revision_test', true ) );
     273        $this->assertSame( '', get_post_meta( $post_id, 'meta_revision_test', true ) );
    274274
    275275        /*
     
    303303         * Verify that previous post meta is NOT restored.
    304304         */
    305         $this->assertEquals( 'update 6', get_post_meta( $post_id, 'meta_revision_test', true ) );
     305        $this->assertSame( 'update 6', get_post_meta( $post_id, 'meta_revision_test', true ) );
    306306
    307307        // Add the custom field to be revised via the wp_post_revision_meta_keys filter.
     
    331331         * Verify that multiple metas stored correctly.
    332332         */
    333         $this->assertEquals( array( 'update 7', 'update 7 number 2', 'update 7 number 3' ), get_post_meta( $post_id, 'meta_revision_test' ) );
     333        $this->assertSame( array( 'update 7', 'update 7 number 2', 'update 7 number 3' ), get_post_meta( $post_id, 'meta_revision_test' ) );
    334334
    335335        /*
     
    374374         */
    375375        $stored_array = get_post_meta( $post_id, 'meta_revision_test' );
    376         $this->assertEquals( $test_array, $stored_array[0] );
     376        $this->assertSame( $test_array, $stored_array[0] );
    377377        /*
    378378
     
    391391        $expect       = array( 'test1', 'test2', 'test3' );
    392392
    393         $this->assertEquals( $expect, $stored_array );
     393        $this->assertSame( $expect, $stored_array );
    394394
    395395        // Restore the previous revision.
     
    401401        $expect       = array( 'test1', 'test2', 'test3' );
    402402
    403         $this->assertEquals( $expect, $stored_array );
     403        $this->assertSame( $expect, $stored_array );
    404404
    405405        // Cleanup!
     
    483483        $expect       = array( 'test1', 'test2', 'test3' );
    484484
    485         $this->assertEquals( $expect, $stored_array );
     485        $this->assertSame( $expect, $stored_array );
    486486
    487487        // Restore the previous revision.
     
    490490        wp_restore_post_revision( $last_revision->ID );
    491491        $stored_data = get_post_meta( $post_id, 'foo' );
    492         $this->assertEquals( '', $stored_data[0] );
     492        $this->assertSame( '', $stored_data[0] );
    493493    }
    494494
     
    527527        // Check that the meta is blank.
    528528        $stored_data = get_post_meta( $post_id, 'meta_revision_test', true );
    529         $this->assertEquals( '', $stored_data );
     529        $this->assertSame( '', $stored_data );
    530530
    531531        // Also verify that the latest revision has blank stored for the meta.
     
    533533        $last_revision = array_shift( $revisions );
    534534        $stored_data   = get_post_meta( $last_revision->ID, 'meta_revision_test', true );
    535         $this->assertEquals( '', $stored_data );
     535        $this->assertSame( '', $stored_data );
    536536
    537537        // Delete the meta.
     
    547547
    548548        // Check that the default meta value is returned.
    549         $this->assertEquals( 'default value', get_post_meta( $post_id, 'meta_revision_test', true ) );
     549        $this->assertSame( 'default value', get_post_meta( $post_id, 'meta_revision_test', true ) );
    550550
    551551        // Also verify that the latest revision has the default value returned for the meta.
     
    554554
    555555        // No ,eta data should be stored in the revision.
    556         $this->assertEquals( array(), get_post_meta( $last_revision->ID ) );
     556        $this->assertSame( array(), get_post_meta( $last_revision->ID ) );
    557557
    558558        // Set the test meta again.
     
    566566
    567567        // Verify the default meta value is still returned.
    568         $this->assertEquals( 'default value', get_post_meta( $post_id, 'meta_revision_test', true ) );
     568        $this->assertSame( 'default value', get_post_meta( $post_id, 'meta_revision_test', true ) );
    569569    }
    570570
     
    599599        $revision        = array_shift( $revisions );
    600600        $revisioned_meta = get_post_meta( $revision->ID, $meta_key, true );
    601         $this->assertEquals( $expected_is_revisioned, 'bar' === $revisioned_meta );
     601        $this->assertSame( $expected_is_revisioned, 'bar' === $revisioned_meta );
    602602
    603603        // Reset global so subsequent data tests do not get polluted.
     
    691691            $last_revision = array_shift( $revisions );
    692692                wp_restore_post_revision( $last_revision->ID );
    693             $this->assertEquals( $expected, get_post_meta( $page_id, 'meta_revision_test', true ) );
     693            $this->assertSame( $expected, get_post_meta( $page_id, 'meta_revision_test', true ) );
    694694        } else {
    695695            $this->assertEmpty( $revisions );
Note: See TracChangeset for help on using the changeset viewer.