Make WordPress Core

Changeset 51220


Ignore:
Timestamp:
06/23/2021 03:59:39 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertEquals() with assertSameSets() in text widget tests.

This ensures that not only the array values being compared are equal, but also that their type is the same.

Going forward, stricter type checking by using assertSame(), assertSameSets(), or assertSameSetsWithIndex() should generally be preferred, to make the tests more reliable.

Follow-up to [40631], [41132], [48939], [51137].

See #52482, #52625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets/text-widget.php

    r49215 r51220  
    732732        $result   = $widget->update( $instance, array() );
    733733        $this->assertSame( $expected, $result );
    734         $this->assertTrue( ! empty( $expected['filter'] ), 'Expected filter prop to be truthy, to handle case where 4.8 is downgraded to 4.7.' );
     734        $this->assertNotEmpty( $expected['filter'], 'Expected filter prop to be truthy, to handle case where 4.8 is downgraded to 4.7.' );
    735735
    736736        add_filter( 'map_meta_cap', array( $this, 'grant_unfiltered_html_cap' ), 10, 2 );
     
    766766        );
    767767        $result   = $widget->update( $instance, array() );
    768         $this->assertSame( $instance, $result, 'Updating a widget without visual prop and explicit filter=false leaves visual prop absent' );
     768        $this->assertSameSets( $instance, $result, 'Updating a widget without visual prop and explicit filter=false leaves visual prop absent' );
    769769
    770770        // --
     
    775775        );
    776776        $result   = $widget->update( $instance, array() );
    777         $this->assertSame( $instance, $result, 'Updating a widget without visual prop and explicit filter=true leaves legacy prop absent.' );
     777        $this->assertSameSets( $instance, $result, 'Updating a widget without visual prop and explicit filter=true leaves legacy prop absent.' );
    778778
    779779        // --
     
    796796        );
    797797        $result       = $widget->update( $instance, $old_instance );
    798         $this->assertSame( $expected, $result, 'Updating a pre-existing widget with visual mode forces filter to be true.' );
     798        $this->assertSameSets( $expected, $result, 'Updating a pre-existing widget with visual mode forces filter to be true.' );
    799799
    800800        // --
     
    817817            )
    818818        );
    819         $this->assertSame( $expected, $result, 'Updating a pre-existing visual widget retains visual mode when updated.' );
     819        $this->assertSameSets( $expected, $result, 'Updating a pre-existing visual widget retains visual mode when updated.' );
    820820
    821821        // --
     
    838838            )
    839839        );
    840         $this->assertSame( $expected, $result, 'Updating a pre-existing visual widget retains visual=true and supplies missing filter=true.' );
     840        $this->assertSameSets( $expected, $result, 'Updating a pre-existing visual widget retains visual=true and supplies missing filter=true.' );
    841841
    842842        // --
     
    853853        );
    854854        $result   = $widget->update( $instance, array() );
    855         $this->assertEquals( $expected, $result, 'Updating a widget with explicit visual=true and absent filter prop causes filter to be set to true.' );
     855        $this->assertSameSets( $expected, $result, 'Updating a widget with explicit visual=true and absent filter prop causes filter to be set to true.' );
    856856
    857857        // --
     
    868868            )
    869869        );
    870         $this->assertEquals( $expected, $result, 'Updating a widget in legacy mode results in filter=false as if checkbox not checked.' );
     870        $this->assertSameSets( $expected, $result, 'Updating a widget in legacy mode results in filter=false as if checkbox not checked.' );
    871871
    872872        // --
     
    891891            )
    892892        );
    893         $this->assertSame( $expected, $result, 'Updating a widget that previously had legacy form results in filter allowed to be false.' );
     893        $this->assertSameSets( $expected, $result, 'Updating a widget that previously had legacy form results in filter allowed to be false.' );
    894894
    895895        // --
     
    907907            )
    908908        );
    909         $this->assertSame( $expected, $result, 'Updating a widget that had \'content\' as its filter value persists non-legacy mode. This only existed in WP 4.8.0.' );
     909        $this->assertSameSets( $expected, $result, 'Updating a widget that had \'content\' as its filter value persists non-legacy mode. This only existed in WP 4.8.0.' );
    910910
    911911        // --
     
    928928            )
    929929        );
    930         $this->assertEquals( $expected, $result, 'Updating a pre-existing widget with the filter=content prop in WP 4.8.0 upgrades to filter=true&visual=true.' );
     930        $this->assertSameSets( $expected, $result, 'Updating a pre-existing widget with the filter=content prop in WP 4.8.0 upgrades to filter=true&visual=true.' );
    931931
    932932        // --
     
    944944            )
    945945        );
    946         $this->assertSame( $expected, $result, 'Updating a widget with filter=content (from WP 4.8.0) upgrades to filter=true&visual=true.' );
     946        $this->assertSameSets( $expected, $result, 'Updating a widget with filter=content (from WP 4.8.0) upgrades to filter=true&visual=true.' );
    947947    }
    948948
Note: See TracChangeset for help on using the changeset viewer.