mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Tests: Use assertSame() in some newly introduced 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. Follow-up to [48937], [48939], [48940], [48944]. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@49547 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -123,8 +123,8 @@ class Block_Supported_Styles_Test extends WP_UnitTestCase {
|
||||
$class_list = $this->get_attribute_from_block( 'class', $styled_block );
|
||||
$style_list = $this->get_attribute_from_block( 'style', $styled_block );
|
||||
|
||||
$this->assertEquals( $expected_classes, $class_list );
|
||||
$this->assertEquals( $expected_styles, $style_list );
|
||||
$this->assertSame( $expected_classes, $class_list );
|
||||
$this->assertSame( $expected_styles, $style_list );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,18 +138,18 @@ class Block_Supported_Styles_Test extends WP_UnitTestCase {
|
||||
$styled_block = $this->render_example_block( $block );
|
||||
|
||||
// Ensure blocks to not add extra whitespace.
|
||||
$this->assertEquals( $styled_block, trim( $styled_block ) );
|
||||
$this->assertSame( $styled_block, trim( $styled_block ) );
|
||||
|
||||
$content = $this->get_content_from_block( $styled_block );
|
||||
$class_list = $this->get_attribute_from_block( 'class', $styled_block );
|
||||
$style_list = $this->get_attribute_from_block( 'style', $styled_block );
|
||||
|
||||
$this->assertEquals( self::BLOCK_CONTENT, $content );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( self::BLOCK_CONTENT, $content );
|
||||
$this->assertSameSets(
|
||||
explode( ' ', $expected_classes ),
|
||||
explode( ' ', $class_list )
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array_map( 'trim', explode( ';', $expected_styles ) ),
|
||||
array_map( 'trim', explode( ';', $style_list ) )
|
||||
);
|
||||
|
||||
@@ -451,8 +451,8 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
$_SERVER['PHP_AUTH_USER'] = 'http_auth_login';
|
||||
$_SERVER['PHP_AUTH_PW'] = 'http_auth_pass';
|
||||
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->assertSame(
|
||||
null,
|
||||
wp_validate_application_password( null ),
|
||||
'Regular user account password should not be allowed for API authentication'
|
||||
);
|
||||
@@ -460,7 +460,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
// Not try with an App password instead.
|
||||
$_SERVER['PHP_AUTH_PW'] = $user_app_password;
|
||||
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
$user_id,
|
||||
wp_validate_application_password( null ),
|
||||
'Application passwords should be allowed for API authentication'
|
||||
@@ -491,7 +491,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, 'idonotexist', 'password' );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'invalid_username', $error->get_error_code() );
|
||||
$this->assertSame( 'invalid_username', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,7 +502,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, 'idonotexist@example.org', 'password' );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'invalid_email', $error->get_error_code() );
|
||||
$this->assertSame( 'invalid_email', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,7 +514,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
|
||||
$this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -527,7 +527,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'application_passwords_disabled', $error->get_error_code() );
|
||||
$this->assertSame( 'application_passwords_disabled', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,7 +539,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, self::$_user->user_login, 'password' );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'incorrect_password', $error->get_error_code() );
|
||||
$this->assertSame( 'incorrect_password', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +560,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$error = wp_authenticate_application_password( null, self::$_user->user_login, $password );
|
||||
$this->assertWPError( $error );
|
||||
$this->assertEquals( 'my_code', $error->get_error_code() );
|
||||
$this->assertSame( 'my_code', $error->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,7 +574,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$user = wp_authenticate_application_password( null, self::$_user->user_login, $password );
|
||||
$this->assertInstanceOf( WP_User::class, $user );
|
||||
$this->assertEquals( self::$user_id, $user->ID );
|
||||
$this->assertSame( self::$user_id, $user->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,7 +588,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$user = wp_authenticate_application_password( null, self::$_user->user_email, $password );
|
||||
$this->assertInstanceOf( WP_User::class, $user );
|
||||
$this->assertEquals( self::$user_id, $user->ID );
|
||||
$this->assertSame( self::$user_id, $user->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,6 +602,6 @@ class Tests_Auth extends WP_UnitTestCase {
|
||||
|
||||
$user = wp_authenticate_application_password( null, self::$_user->user_email, WP_Application_Passwords::chunk_password( $password ) );
|
||||
$this->assertInstanceOf( WP_User::class, $user );
|
||||
$this->assertEquals( self::$user_id, $user->ID );
|
||||
$this->assertSame( self::$user_id, $user->ID );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1763,7 +1763,7 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
* @dataProvider data_test_wp_is_json_media_type
|
||||
*/
|
||||
public function test_wp_is_json_media_type( $input, $expected ) {
|
||||
$this->assertEquals( $expected, wp_is_json_media_type( $input ) );
|
||||
$this->assertSame( $expected, wp_is_json_media_type( $input ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ if ( is_multisite() ) :
|
||||
|
||||
restore_current_blog();
|
||||
$this->assertNotEmpty( $spam_permalink );
|
||||
$this->assertEquals( $post_data['post_title'], $post->post_title );
|
||||
$this->assertSame( $post_data['post_title'], $post->post_title );
|
||||
|
||||
update_blog_status( $spam_blog_id, 'spam', 1 );
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$admin, array( 'name' => 'App' ) );
|
||||
|
||||
$response = rest_do_request( '/wp/v2/users/me/application-passwords' );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 1, $response->get_data() );
|
||||
$this->check_response( $response->get_data()[0], $item );
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$admin, array( 'name' => 'App' ) );
|
||||
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$admin ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 1, $response->get_data() );
|
||||
$this->check_response( $response->get_data()[0], $item );
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$subscriber_id, array( 'name' => 'App' ) );
|
||||
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 1, $response->get_data() );
|
||||
$this->check_response( $response->get_data()[0], $item );
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$subscriber_id, array( 'name' => 'App' ) );
|
||||
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 1, $response->get_data() );
|
||||
$this->check_response( $response->get_data()[0], $item );
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$uuid = $item['uuid'];
|
||||
$response = rest_do_request( '/wp/v2/users/me/application-passwords/' . $uuid );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), $item );
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$uuid = $item['uuid'];
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $uuid ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), $item );
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$uuid = $item['uuid'];
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), $item );
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$uuid = $item['uuid'];
|
||||
$response = rest_do_request( sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), $item );
|
||||
}
|
||||
|
||||
@@ -318,13 +318,13 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
);
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
|
||||
$passwords = WP_Application_Passwords::get_user_application_passwords( self::$admin );
|
||||
$this->assertCount( 1, $passwords );
|
||||
$this->check_response( $response->get_data(), $passwords[0], true );
|
||||
$this->assertEquals( 'App', $response->get_data()['name'] );
|
||||
$this->assertEquals( $app_id, $response->get_data()['app_id'] );
|
||||
$this->assertSame( 'App', $response->get_data()['name'] );
|
||||
$this->assertSame( $app_id, $response->get_data()['app_id'] );
|
||||
$this->assertNull( $response->get_data()['last_used'] );
|
||||
$this->assertNull( $response->get_data()['last_ip'] );
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request->set_body_params( array( 'name' => 'App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
|
||||
$passwords = WP_Application_Passwords::get_user_application_passwords( self::$admin );
|
||||
$this->assertCount( 1, $passwords );
|
||||
@@ -356,7 +356,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request->set_body_params( array( 'name' => 'App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
|
||||
$passwords = WP_Application_Passwords::get_user_application_passwords( self::$subscriber_id );
|
||||
$this->assertCount( 1, $passwords );
|
||||
@@ -373,7 +373,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request->set_body_params( array( 'name' => 'App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
|
||||
$passwords = WP_Application_Passwords::get_user_application_passwords( self::$subscriber_id );
|
||||
$this->assertCount( 1, $passwords );
|
||||
@@ -415,9 +415,9 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', '/wp/v2/users/me/application-passwords/' . $uuid );
|
||||
$request->set_body_params( array( 'name' => 'New App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$admin, $item['uuid'] ) );
|
||||
$this->assertEquals( 'New App', $response->get_data()['name'] );
|
||||
$this->assertSame( 'New App', $response->get_data()['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,9 +431,9 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $uuid ) );
|
||||
$request->set_body_params( array( 'name' => 'New App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$admin, $item['uuid'] ) );
|
||||
$this->assertEquals( 'New App', $response->get_data()['name'] );
|
||||
$this->assertSame( 'New App', $response->get_data()['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,9 +447,9 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$request->set_body_params( array( 'name' => 'New App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$subscriber_id, $item['uuid'] ) );
|
||||
$this->assertEquals( 'New App', $response->get_data()['name'] );
|
||||
$this->assertSame( 'New App', $response->get_data()['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,9 +463,9 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$request->set_body_params( array( 'name' => 'New App' ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data(), WP_Application_Passwords::get_user_application_password( self::$subscriber_id, $item['uuid'] ) );
|
||||
$this->assertEquals( 'New App', $response->get_data()['name'] );
|
||||
$this->assertSame( 'New App', $response->get_data()['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -531,7 +531,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', '/wp/v2/users/me/application-passwords/' . $uuid );
|
||||
$request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( '', $response->get_data()['app_id'] );
|
||||
$this->assertSame( '', $response->get_data()['app_id'] );
|
||||
|
||||
$app_id = wp_generate_uuid4();
|
||||
|
||||
@@ -547,7 +547,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$request = new WP_REST_Request( 'PUT', '/wp/v2/users/me/application-passwords/' . $uuid );
|
||||
$request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( $app_id, $response->get_data()['app_id'] );
|
||||
$this->assertSame( $app_id, $response->get_data()['app_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +560,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$uuid = $item['uuid'];
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me/application-passwords/' . $uuid );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertArrayHasKey( 'deleted', $response->get_data() );
|
||||
$this->assertTrue( $response->get_data()['deleted'] );
|
||||
$this->assertArrayHasKey( 'previous', $response->get_data() );
|
||||
@@ -579,7 +579,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$uuid = $item ['uuid'];
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$admin, $uuid ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data()['previous'], $item );
|
||||
}
|
||||
|
||||
@@ -593,7 +593,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$uuid = $item['uuid'];
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data()['previous'], $item );
|
||||
}
|
||||
|
||||
@@ -607,7 +607,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$uuid = $item['uuid'];
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords/%s', self::$subscriber_id, $uuid ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->check_response( $response->get_data()['previous'], $item );
|
||||
}
|
||||
|
||||
@@ -669,11 +669,11 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/users/me/application-passwords' );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertArrayHasKey( 'deleted', $response->get_data() );
|
||||
$this->assertTrue( $response->get_data()['deleted'] );
|
||||
$this->assertArrayHasKey( 'count', $response->get_data() );
|
||||
$this->assertEquals( 2, $response->get_data()['count'] );
|
||||
$this->assertSame( 2, $response->get_data()['count'] );
|
||||
|
||||
$this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
|
||||
}
|
||||
@@ -687,7 +687,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$admin ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
|
||||
}
|
||||
|
||||
@@ -700,7 +700,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
|
||||
}
|
||||
|
||||
@@ -713,7 +713,7 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
|
||||
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d/application-passwords', self::$subscriber_id ) );
|
||||
$response = rest_do_request( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertCount( 0, WP_Application_Passwords::get_user_application_passwords( self::$admin ) );
|
||||
}
|
||||
|
||||
@@ -818,19 +818,19 @@ class WP_Test_REST_Application_Passwords_Controller extends WP_Test_REST_Control
|
||||
$this->assertArrayHasKey( 'last_used', $response );
|
||||
$this->assertArrayHasKey( 'last_ip', $response );
|
||||
|
||||
$this->assertEquals( $item['uuid'], $response['uuid'] );
|
||||
$this->assertEquals( $item['app_id'], $response['app_id'] );
|
||||
$this->assertEquals( $item['name'], $response['name'] );
|
||||
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s', $item['created'] ), $response['created'] );
|
||||
$this->assertSame( $item['uuid'], $response['uuid'] );
|
||||
$this->assertSame( $item['app_id'], $response['app_id'] );
|
||||
$this->assertSame( $item['name'], $response['name'] );
|
||||
$this->assertSame( gmdate( 'Y-m-d\TH:i:s', $item['created'] ), $response['created'] );
|
||||
|
||||
if ( $item['last_used'] ) {
|
||||
$this->assertEquals( gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ), $response['last_used'] );
|
||||
$this->assertSame( gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ), $response['last_used'] );
|
||||
} else {
|
||||
$this->assertNull( $response['last_used'] );
|
||||
}
|
||||
|
||||
if ( $item['last_ip'] ) {
|
||||
$this->assertEquals( $item['last_ip'], $response['last_ip'] );
|
||||
$this->assertSame( $item['last_ip'], $response['last_ip'] );
|
||||
} else {
|
||||
$this->assertNull( $response['last_ip'] );
|
||||
}
|
||||
|
||||
@@ -1028,7 +1028,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
|
||||
$this->assertNotWPError( $response->as_error() );
|
||||
$this->assertEquals( 'inherit', $response->get_data()['status'] );
|
||||
$this->assertSame( 'inherit', $response->get_data()['status'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1440,7 +1440,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertEquals( '0', $response->get_data()['content']['raw'] );
|
||||
$this->assertSame( '0', $response->get_data()['content']['raw'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1465,7 +1465,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertEquals( '', $response->get_data()['content']['raw'] );
|
||||
$this->assertSame( '', $response->get_data()['content']['raw'] );
|
||||
}
|
||||
|
||||
public function test_create_item_invalid_date() {
|
||||
@@ -3325,7 +3325,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
||||
);
|
||||
|
||||
if ( $comment->comment_post_ID ) {
|
||||
$this->assertEquals( rest_url( '/wp/v2/posts/' . $comment->comment_post_ID ), $links['up'][0]['href'] );
|
||||
$this->assertSame( rest_url( '/wp/v2/posts/' . $comment->comment_post_ID ), $links['up'][0]['href'] );
|
||||
}
|
||||
|
||||
if ( 'edit' === $context ) {
|
||||
|
||||
@@ -248,7 +248,7 @@ class WP_Test_REST_Controller extends WP_Test_REST_TestCase {
|
||||
$controller = new WP_REST_Test_Controller();
|
||||
$args = rest_get_endpoint_args_for_schema( $controller->get_item_schema() );
|
||||
|
||||
$this->assertEquals( 'A pretty string.', $args['somestring']['description'] );
|
||||
$this->assertSame( 'A pretty string.', $args['somestring']['description'] );
|
||||
$this->assertFalse( isset( $args['someinteger']['description'] ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
$this->request->set_attributes( array( 'accept_json' => true ) );
|
||||
|
||||
// Check that JSON takes precedence.
|
||||
$this->assertEquals( $source, $this->request->get_param( 'source' ) );
|
||||
$this->assertSame( $source, $this->request->get_param( 'source' ) );
|
||||
$this->assertEquals( $accept_json, $this->request->get_param( 'has_json_params' ) );
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
$this->request->set_header( 'Content-Type', $content_type );
|
||||
|
||||
// Check for JSON content-type.
|
||||
$this->assertEquals( $is_json, $this->request->is_json_content_type() );
|
||||
$this->assertSame( $is_json, $this->request->is_json_content_type() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -926,6 +926,6 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
|
||||
$valid = $request->has_valid_params();
|
||||
$this->assertWPError( $valid );
|
||||
$this->assertEquals( 'rest_invalid_param', $valid->get_error_code() );
|
||||
$this->assertSame( 'rest_invalid_param', $valid->get_error_code() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,8 +569,8 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'type' => 'term',
|
||||
)
|
||||
);
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
0 => 1, // That is the default category.
|
||||
self::$my_category_id,
|
||||
@@ -594,8 +594,8 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
0 => 1, // That is the default category.
|
||||
self::$my_category_id,
|
||||
@@ -634,8 +634,8 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'subtype' => 'category,post_tag',
|
||||
)
|
||||
);
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
0 => 1, // This is the default category.
|
||||
self::$my_category_id,
|
||||
@@ -659,8 +659,8 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
self::$my_category_id,
|
||||
),
|
||||
@@ -682,8 +682,8 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEqualSets(
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array(
|
||||
self::$my_tag_id,
|
||||
),
|
||||
@@ -705,7 +705,7 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertEmpty( $response->get_data() );
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'type' => 'post-format',
|
||||
)
|
||||
);
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertContains(
|
||||
'Aside',
|
||||
wp_list_pluck( $response->get_data(), 'title' )
|
||||
@@ -742,7 +742,7 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertContains(
|
||||
'Aside',
|
||||
wp_list_pluck( $response->get_data(), 'title' )
|
||||
@@ -764,7 +764,7 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertEmpty( $response->get_data() );
|
||||
}
|
||||
|
||||
|
||||
@@ -1550,7 +1550,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$events = $mock_hook->get_events();
|
||||
$this->assertCount( 1, $events );
|
||||
$this->assertWPError( $events[0]['args'][0] );
|
||||
$this->assertEquals( 'rest_invalid_handler', $events[0]['args'][0]->get_error_code() );
|
||||
$this->assertSame( 'rest_invalid_handler', $events[0]['args'][0]->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1614,7 +1614,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$events = $mock_hook->get_events();
|
||||
$this->assertCount( 1, $events );
|
||||
$this->assertWPError( $events[0]['args'][0] );
|
||||
$this->assertEquals( 'rest_invalid_param', $events[0]['args'][0]->get_error_code() );
|
||||
$this->assertSame( 'rest_invalid_param', $events[0]['args'][0]->get_error_code() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1653,12 +1653,12 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
|
||||
$response = rest_do_request( $request );
|
||||
|
||||
$this->assertEquals( 207, $response->get_status() );
|
||||
$this->assertSame( 207, $response->get_status() );
|
||||
|
||||
if ( $allowed ) {
|
||||
$this->assertEquals( 'data', $response->get_data()['responses'][0]['body'] );
|
||||
$this->assertSame( 'data', $response->get_data()['responses'][0]['body'] );
|
||||
} else {
|
||||
$this->assertEquals( 'rest_batch_not_allowed', $response->get_data()['responses'][0]['body']['code'] );
|
||||
$this->assertSame( 'rest_batch_not_allowed', $response->get_data()['responses'][0]['body']['code'] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1723,12 +1723,12 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 207, $response->get_status() );
|
||||
$this->assertSame( 207, $response->get_status() );
|
||||
$this->assertArrayHasKey( 'failed', $data );
|
||||
$this->assertEquals( 'validation', $data['failed'] );
|
||||
$this->assertSame( 'validation', $data['failed'] );
|
||||
$this->assertCount( 2, $data['responses'] );
|
||||
$this->assertNull( $data['responses'][0] );
|
||||
$this->assertEquals( 400, $data['responses'][1]['status'] );
|
||||
$this->assertSame( 400, $data['responses'][1]['status'] );
|
||||
$this->assertFalse( get_option( 'test_project' ) );
|
||||
}
|
||||
|
||||
@@ -1779,11 +1779,11 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 207, $response->get_status() );
|
||||
$this->assertSame( 207, $response->get_status() );
|
||||
$this->assertArrayNotHasKey( 'failed', $data );
|
||||
$this->assertCount( 2, $data['responses'] );
|
||||
$this->assertEquals( 'gutenberg', $data['responses'][0]['body'] );
|
||||
$this->assertEquals( 'WordPress', $data['responses'][1]['body'] );
|
||||
$this->assertSame( 'gutenberg', $data['responses'][0]['body'] );
|
||||
$this->assertSame( 'WordPress', $data['responses'][1]['body'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1796,12 +1796,12 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
array(
|
||||
'methods' => array( 'POST', 'DELETE' ),
|
||||
'callback' => function ( WP_REST_Request $request ) {
|
||||
$this->assertEquals( 'DELETE', $request->get_method() );
|
||||
$this->assertEquals( '/test-ns/v1/test/5', $request->get_route() );
|
||||
$this->assertEquals( array( 'id' => '5' ), $request->get_url_params() );
|
||||
$this->assertEquals( array( 'query' => 'param' ), $request->get_query_params() );
|
||||
$this->assertEquals( array( 'project' => 'gutenberg' ), $request->get_body_params() );
|
||||
$this->assertEquals( array( 'my_header' => array( 'my-value' ) ), $request->get_headers() );
|
||||
$this->assertSame( 'DELETE', $request->get_method() );
|
||||
$this->assertSame( '/test-ns/v1/test/5', $request->get_route() );
|
||||
$this->assertSame( array( 'id' => '5' ), $request->get_url_params() );
|
||||
$this->assertSame( array( 'query' => 'param' ), $request->get_query_params() );
|
||||
$this->assertSame( array( 'project' => 'gutenberg' ), $request->get_body_params() );
|
||||
$this->assertSame( array( 'my_header' => array( 'my-value' ) ), $request->get_headers() );
|
||||
|
||||
return new WP_REST_Response( 'test' );
|
||||
},
|
||||
@@ -1830,8 +1830,8 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
|
||||
$this->assertEquals( 207, $response->get_status() );
|
||||
$this->assertEquals( 'test', $response->get_data()['responses'][0]['body'] );
|
||||
$this->assertSame( 207, $response->get_status() );
|
||||
$this->assertSame( 'test', $response->get_data()['responses'][0]['body'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1883,12 +1883,12 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 207, $response->get_status() );
|
||||
$this->assertSame( 207, $response->get_status() );
|
||||
$this->assertArrayNotHasKey( 'failed', $data );
|
||||
$this->assertCount( 2, $data['responses'] );
|
||||
$this->assertEquals( 'gutenberg', $data['responses'][0]['body'] );
|
||||
$this->assertEquals( 400, $data['responses'][1]['status'] );
|
||||
$this->assertEquals( 'gutenberg', get_option( 'test_project' ) );
|
||||
$this->assertSame( 'gutenberg', $data['responses'][0]['body'] );
|
||||
$this->assertSame( 400, $data['responses'][1]['status'] );
|
||||
$this->assertSame( 'gutenberg', get_option( 'test_project' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -1928,7 +1928,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
);
|
||||
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 400, $response->get_status() );
|
||||
$this->assertSame( 400, $response->get_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -97,6 +97,6 @@ class WP_Test_REST_Site_Health_Controller extends WP_Test_REST_TestCase {
|
||||
public function test() {
|
||||
wp_set_current_user( self::$admin );
|
||||
$response = rest_do_request( '/wp-site-health/v1/tests/dotorg-communication' );
|
||||
$this->assertEquals( 'dotorg_communication', $response->get_data()['test'] );
|
||||
$this->assertSame( 'dotorg_communication', $response->get_data()['test'] );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user