Skip to content

Commit 1011120

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51220 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bdf7dd6 commit 1011120

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

tests/phpunit/tests/widgets/text-widget.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ function test_update() {
731731
);
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 );
737737
$this->assertTrue( current_user_can( 'unfiltered_html' ) );
@@ -765,7 +765,7 @@ function test_update_legacy() {
765765
'filter' => false,
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
// --
771771
$instance = array(
@@ -774,7 +774,7 @@ function test_update_legacy() {
774774
'filter' => true,
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
// --
780780
$instance = array(
@@ -795,7 +795,7 @@ function test_update_legacy() {
795795
)
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
// --
801801
$instance = array(
@@ -816,7 +816,7 @@ function test_update_legacy() {
816816
'visual' => true,
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
// --
822822
$instance = array(
@@ -837,7 +837,7 @@ function test_update_legacy() {
837837
'filter' => true,
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
// --
843843
$instance = array(
@@ -852,7 +852,7 @@ function test_update_legacy() {
852852
)
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
// --
858858
$instance = array(
@@ -867,7 +867,7 @@ function test_update_legacy() {
867867
'filter' => false,
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
// --
873873
$instance = array(
@@ -890,7 +890,7 @@ function test_update_legacy() {
890890
'filter' => false,
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
// --
896896
$instance = array(
@@ -906,7 +906,7 @@ function test_update_legacy() {
906906
'visual' => true,
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
// --
912912
$instance = array(
@@ -927,7 +927,7 @@ function test_update_legacy() {
927927
'filter' => true,
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
// --
933933
$instance = array(
@@ -943,7 +943,7 @@ function test_update_legacy() {
943943
'visual' => true,
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

949949
/**

0 commit comments

Comments
 (0)