mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-07 01:39:04 +00:00
Tests: Use more appropriate assertions in various tests.
This replaces instances of `assertSame( [number], count( ... ) )` with `assertCount()` to use native PHPUnit functionality. Follow-up to [51335], [51337]. See #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51367 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -387,12 +387,12 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 10, count( $response->get_data() ) );
|
||||
$this->assertCount( 10, $response->get_data() );
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'per_page', 5 );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 5, count( $response->get_data() ) );
|
||||
$this->assertCount( 5, $response->get_data() );
|
||||
}
|
||||
|
||||
public function test_get_items_page() {
|
||||
@@ -402,7 +402,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'per_page', 5 );
|
||||
$request->set_param( 'page', 2 );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 5, count( $response->get_data() ) );
|
||||
$this->assertCount( 5, $response->get_data() );
|
||||
$prev_link = add_query_arg(
|
||||
array(
|
||||
'per_page' => 5,
|
||||
@@ -598,14 +598,14 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'include', array( $id2, $id1 ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 2, count( $data ) );
|
||||
$this->assertCount( 2, $data );
|
||||
$this->assertSame( $id1, $data[0]['id'] );
|
||||
|
||||
// 'orderby' => 'include'.
|
||||
$request->set_param( 'orderby', 'include' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 2, count( $data ) );
|
||||
$this->assertCount( 2, $data );
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
|
||||
// Invalid 'include' should error.
|
||||
@@ -618,7 +618,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
wp_set_current_user( 0 );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 0, count( $data ) );
|
||||
$this->assertCount( 0, $data );
|
||||
|
||||
}
|
||||
|
||||
@@ -655,14 +655,14 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'search', 'yololololo' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 0, count( $response->get_data() ) );
|
||||
$this->assertCount( 0, $response->get_data() );
|
||||
|
||||
$yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) );
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'search', 'yololololo' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 1, count( $response->get_data() ) );
|
||||
$this->assertCount( 1, $response->get_data() );
|
||||
// Default to wildcard search.
|
||||
$adam_id = $this->factory->user->create(
|
||||
array(
|
||||
@@ -675,7 +675,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'search', 'ada' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $adam_id, $data[0]['id'] );
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'slug', 'foo' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
@@ -812,14 +812,14 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'roles', 'author,subscriber' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 3, count( $data ) );
|
||||
$this->assertCount( 3, $data );
|
||||
$this->assertSame( $tango, $data[1]['id'] );
|
||||
$this->assertSame( $yolo, $data[2]['id'] );
|
||||
|
||||
$request->set_param( 'roles', 'author' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $yolo, $data[0]['id'] );
|
||||
|
||||
wp_set_current_user( 0 );
|
||||
@@ -849,14 +849,14 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'roles', 'ilovesteak,author' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $lolz, $data[0]['id'] );
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'roles', 'steakisgood' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertSame( 0, count( $data ) );
|
||||
$this->assertCount( 0, $data );
|
||||
$this->assertSame( array(), $data );
|
||||
}
|
||||
|
||||
@@ -2620,7 +2620,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertSame( 19, count( $properties ) );
|
||||
$this->assertCount( 19, $properties );
|
||||
$this->assertArrayHasKey( 'avatar_urls', $properties );
|
||||
$this->assertArrayHasKey( 'capabilities', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
|
||||
Reference in New Issue
Block a user