mirror of
git://develop.git.wordpress.org/
synced 2025-03-23 05:20:01 +01:00
Tests: Use assertSameSets()
in some newly introduced 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 `assertSameSets()` or `assertSameSetsWithIndex()` should generally be preferred, to make the tests more reliable. Follow-up to [48939], [49925], [50157], [50959], [50960], [50995], [51079]. See #52625. git-svn-id: https://develop.svn.wordpress.org/trunk@51137 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5bee644258
commit
d4b2fae838
@ -1155,7 +1155,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEqualSets( $post_ids, array_column( $data, 'id' ) );
|
||||
$this->assertSameSets( $post_ids, array_column( $data, 'id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,7 +219,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'theme_uri',
|
||||
'version',
|
||||
);
|
||||
$this->assertEqualSets( $fields, array_keys( $data[0] ) );
|
||||
$this->assertSameSets( $fields, array_keys( $data[0] ) );
|
||||
|
||||
$this->assertContains( 'twentytwenty', wp_list_pluck( $data, 'stylesheet' ) );
|
||||
$this->assertNotContains( get_stylesheet(), wp_list_pluck( $data, 'stylesheet' ) );
|
||||
@ -1236,8 +1236,8 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
);
|
||||
$fields_links = array( 'collection', 'self' );
|
||||
|
||||
$this->assertEqualSets( $fields, array_keys( $data ) );
|
||||
$this->assertEqualSets( $fields_links, array_keys( $links ) );
|
||||
$this->assertSameSets( $fields, array_keys( $data ) );
|
||||
$this->assertSameSets( $fields_links, array_keys( $links ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -402,7 +402,7 @@ class WP_Test_REST_Widget_Types_Controller extends WP_Test_REST_Controller_Testc
|
||||
"\t\t\t</form></div>",
|
||||
$data['preview']
|
||||
);
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
'encoded' => base64_encode( serialize( array( 'title' => 'Test title' ) ) ),
|
||||
'hash' => wp_hash( serialize( array( 'title' => 'Test title' ) ) ),
|
||||
@ -438,7 +438,7 @@ class WP_Test_REST_Widget_Types_Controller extends WP_Test_REST_Controller_Testc
|
||||
"\t\t\t</form></div>",
|
||||
$data['preview']
|
||||
);
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
'encoded' => base64_encode( serialize( array( 'title' => 'Updated title' ) ) ),
|
||||
'hash' => wp_hash( serialize( array( 'title' => 'Updated title' ) ) ),
|
||||
@ -482,7 +482,7 @@ class WP_Test_REST_Widget_Types_Controller extends WP_Test_REST_Controller_Testc
|
||||
"\t\t\t</form></div>",
|
||||
$data['preview']
|
||||
);
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
'encoded' => base64_encode( serialize( array( 'title' => 'Test title' ) ) ),
|
||||
'hash' => wp_hash( serialize( array( 'title' => 'Test title' ) ) ),
|
||||
|
@ -272,12 +272,13 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$data = $this->remove_links( $data );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
array(
|
||||
'id' => 'block-1',
|
||||
'id_base' => 'block',
|
||||
'sidebar' => 'sidebar-1',
|
||||
'rendered' => '<p>Block test</p>',
|
||||
'instance' => array(
|
||||
'encoded' => base64_encode(
|
||||
serialize(
|
||||
@ -297,12 +298,12 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'content' => $block_content,
|
||||
),
|
||||
),
|
||||
'rendered' => '<p>Block test</p>',
|
||||
),
|
||||
array(
|
||||
'id' => 'rss-1',
|
||||
'id_base' => 'rss',
|
||||
'sidebar' => 'sidebar-1',
|
||||
'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
|
||||
'instance' => array(
|
||||
'encoded' => base64_encode(
|
||||
serialize(
|
||||
@ -321,14 +322,13 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
),
|
||||
),
|
||||
'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
|
||||
),
|
||||
array(
|
||||
'id' => 'testwidget',
|
||||
'id_base' => 'testwidget',
|
||||
'sidebar' => 'sidebar-1',
|
||||
'instance' => null,
|
||||
'rendered' => '<h1>Default id</h1><span>Default text</span>',
|
||||
'instance' => null,
|
||||
),
|
||||
),
|
||||
$data
|
||||
@ -447,11 +447,12 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/widgets/text-1' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
'id' => 'text-1',
|
||||
'id_base' => 'text',
|
||||
'sidebar' => 'sidebar-1',
|
||||
'rendered' => '<div class="textwidget">Custom text test</div>',
|
||||
'instance' => array(
|
||||
'encoded' => base64_encode(
|
||||
serialize(
|
||||
@ -471,7 +472,6 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'text' => 'Custom text test',
|
||||
),
|
||||
),
|
||||
'rendered' => '<div class="textwidget">Custom text test</div>',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@ -565,7 +565,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'text-2', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated text test',
|
||||
'title' => '',
|
||||
@ -657,7 +657,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'block-7', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
'content' => '<!-- wp:paragraph --><p>Block test</p><!-- /wp:paragraph -->',
|
||||
),
|
||||
@ -721,7 +721,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'text-2', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated text test',
|
||||
'title' => '',
|
||||
@ -756,7 +756,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'text-2', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Text 1',
|
||||
'title' => '',
|
||||
@ -779,7 +779,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'text-3', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Text 2',
|
||||
'title' => '',
|
||||
@ -827,7 +827,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 'text-2', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated text test',
|
||||
'title' => '',
|
||||
@ -874,7 +874,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
$this->assertSame( 'text-1', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated text test',
|
||||
'title' => '',
|
||||
@ -963,7 +963,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
$this->assertSame( 'text-1', $data['id'] );
|
||||
$this->assertSame( 'sidebar-1', $data['sidebar'] );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated text test',
|
||||
'title' => '',
|
||||
@ -1170,7 +1170,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEqualSets(
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'text' => 'Updated \\" \\\' text test',
|
||||
'title' => '',
|
||||
|
@ -61,7 +61,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
$this->assertSameSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
function test_get_stylesheet() {
|
||||
@ -656,7 +656,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
);
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( array() );
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
$this->assertSameSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -673,7 +673,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( $input );
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
$this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -690,7 +690,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( $input );
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
$this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -707,7 +707,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( $input );
|
||||
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
$this->assertSameSetsWithIndex( $expected, $actual['settings']['spacing'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user