mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 17:20:07 +00:00
Tests: First pass at using assertSame() instead of assertEquals() in most of the unit 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. Props johnbillion, jrf, SergeyBiryukov. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -155,7 +155,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
public function test_parse_disposition( $header, $expected ) {
|
||||
$header_list = array( $header );
|
||||
$parsed = WP_REST_Attachments_Controller::get_filename_from_disposition( $header_list );
|
||||
$this->assertEquals( $expected, $parsed );
|
||||
$this->assertSame( $expected, $parsed );
|
||||
}
|
||||
|
||||
public function test_context_param() {
|
||||
@@ -163,8 +163,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
|
||||
$this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
|
||||
$this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
|
||||
$this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
|
||||
// Single.
|
||||
$attachment_id = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
@@ -177,8 +177,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/media/' . $attachment_id );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
|
||||
$this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
|
||||
$this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
|
||||
$this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
|
||||
}
|
||||
|
||||
public function test_registered_query_params() {
|
||||
@@ -187,7 +187,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$data = $response->get_data();
|
||||
$keys = array_keys( $data['endpoints'][0]['args'] );
|
||||
sort( $keys );
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array(
|
||||
'after',
|
||||
'author',
|
||||
@@ -237,7 +237,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$data = $response->get_data();
|
||||
$keys = array_keys( $data['endpoints'][0]['args'] );
|
||||
sort( $keys );
|
||||
$this->assertEquals( array( 'context', 'id' ), $keys );
|
||||
$this->assertSame( array( 'context', 'id' ), $keys );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +258,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$headers = $response->get_headers();
|
||||
|
||||
$this->assertNotEmpty( $headers['Allow'] );
|
||||
$this->assertEquals( $headers['Allow'], 'GET' );
|
||||
$this->assertSame( $headers['Allow'], 'GET' );
|
||||
|
||||
wp_set_current_user( self::$editor_id );
|
||||
$request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/media/%d', $id1 ) );
|
||||
@@ -267,7 +267,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$headers = $response->get_headers();
|
||||
|
||||
$this->assertNotEmpty( $headers['Allow'] );
|
||||
$this->assertEquals( $headers['Allow'], 'GET, POST, PUT, PATCH, DELETE' );
|
||||
$this->assertSame( $headers['Allow'], 'GET, POST, PUT, PATCH, DELETE' );
|
||||
}
|
||||
|
||||
public function test_get_items() {
|
||||
@@ -360,7 +360,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( $id1, $data[0]['id'] );
|
||||
$this->assertSame( $id1, $data[0]['id'] );
|
||||
// 'media_type' => 'video'.
|
||||
$request->set_param( 'media_type', 'video' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
@@ -369,7 +369,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( 'media_type', 'image' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( $id1, $data[0]['id'] );
|
||||
$this->assertSame( $id1, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_items_mime_type() {
|
||||
@@ -383,7 +383,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( $id1, $data[0]['id'] );
|
||||
$this->assertSame( $id1, $data[0]['id'] );
|
||||
// 'mime_type' => 'image/png'.
|
||||
$request->set_param( 'mime_type', 'image/png' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
@@ -392,7 +392,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( 'mime_type', 'image/jpeg' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( $id1, $data[0]['id'] );
|
||||
$this->assertSame( $id1, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_items_parent() {
|
||||
@@ -416,27 +416,27 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
// All attachments.
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 2, count( $response->get_data() ) );
|
||||
$this->assertSame( 2, count( $response->get_data() ) );
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
// Attachments without a parent.
|
||||
$request->set_param( 'parent', 0 );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 1, count( $data ) );
|
||||
$this->assertEquals( $attachment_id2, $data[0]['id'] );
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertSame( $attachment_id2, $data[0]['id'] );
|
||||
// Attachments with parent=post_id.
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$request->set_param( 'parent', $post_id );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 1, count( $data ) );
|
||||
$this->assertEquals( $attachment_id, $data[0]['id'] );
|
||||
$this->assertSame( 1, count( $data ) );
|
||||
$this->assertSame( $attachment_id, $data[0]['id'] );
|
||||
// Attachments with invalid parent.
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 0, count( $data ) );
|
||||
$this->assertSame( 0, count( $data ) );
|
||||
}
|
||||
|
||||
public function test_get_items_invalid_status_param_is_error_response() {
|
||||
@@ -455,7 +455,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertCount( 3, $data );
|
||||
$this->assertEquals( 'rest_invalid_param', $data['code'] );
|
||||
$this->assertSame( 'rest_invalid_param', $data['code'] );
|
||||
}
|
||||
|
||||
public function test_get_items_private_status() {
|
||||
@@ -477,9 +477,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
// Properly authorized users can make the request.
|
||||
wp_set_current_user( self::$editor_id );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( $attachment_id1, $data[0]['id'] );
|
||||
$this->assertSame( $attachment_id1, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_items_multiple_statuses() {
|
||||
@@ -510,15 +510,15 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
// Properly authorized users can make the request.
|
||||
wp_set_current_user( self::$editor_id );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 2, count( $data ) );
|
||||
$this->assertSame( 2, count( $data ) );
|
||||
$ids = array(
|
||||
$data[0]['id'],
|
||||
$data[1]['id'],
|
||||
);
|
||||
sort( $ids );
|
||||
$this->assertEquals( array( $attachment_id1, $attachment_id2 ), $ids );
|
||||
$this->assertSame( array( $attachment_id1, $attachment_id2 ), $ids );
|
||||
}
|
||||
|
||||
public function test_get_items_invalid_date() {
|
||||
@@ -563,7 +563,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertEquals( $id2, $data[0]['id'] );
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_item() {
|
||||
@@ -580,7 +580,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->check_get_post_response( $response );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'image/jpeg', $data['mime_type'] );
|
||||
$this->assertSame( 'image/jpeg', $data['mime_type'] );
|
||||
}
|
||||
|
||||
public function test_get_item_sizes() {
|
||||
@@ -604,10 +604,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$original_image_src = wp_get_attachment_image_src( $attachment_id, 'full' );
|
||||
remove_image_size( 'rest-api-test' );
|
||||
|
||||
$this->assertEquals( $image_src[0], $data['media_details']['sizes']['rest-api-test']['source_url'] );
|
||||
$this->assertEquals( 'image/jpeg', $data['media_details']['sizes']['rest-api-test']['mime_type'] );
|
||||
$this->assertEquals( $original_image_src[0], $data['media_details']['sizes']['full']['source_url'] );
|
||||
$this->assertEquals( 'image/jpeg', $data['media_details']['sizes']['full']['mime_type'] );
|
||||
$this->assertSame( $image_src[0], $data['media_details']['sizes']['rest-api-test']['source_url'] );
|
||||
$this->assertSame( 'image/jpeg', $data['media_details']['sizes']['rest-api-test']['mime_type'] );
|
||||
$this->assertSame( $original_image_src[0], $data['media_details']['sizes']['full']['source_url'] );
|
||||
$this->assertSame( 'image/jpeg', $data['media_details']['sizes']['full']['mime_type'] );
|
||||
}
|
||||
|
||||
public function test_get_item_sizes_with_no_url() {
|
||||
@@ -648,7 +648,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
);
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $id1 );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 401, $response->get_status() );
|
||||
$this->assertSame( 401, $response->get_status() );
|
||||
}
|
||||
|
||||
public function test_get_item_inherit_status_with_invalid_parent() {
|
||||
@@ -664,8 +664,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEquals( $attachment_id, $data['id'] );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSame( $attachment_id, $data['id'] );
|
||||
}
|
||||
|
||||
public function test_get_item_auto_status_with_invalid_parent_not_authenticated_returns_error() {
|
||||
@@ -699,18 +699,18 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertEquals( 'image', $data['media_type'] );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertSame( 'image', $data['media_type'] );
|
||||
|
||||
$attachment = get_post( $data['id'] );
|
||||
$this->assertEquals( 'My title is very cool', $data['title']['raw'] );
|
||||
$this->assertEquals( 'My title is very cool', $attachment->post_title );
|
||||
$this->assertEquals( 'This is a better caption.', $data['caption']['raw'] );
|
||||
$this->assertEquals( 'This is a better caption.', $attachment->post_excerpt );
|
||||
$this->assertEquals( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );
|
||||
$this->assertEquals( 'Without a description, my attachment is descriptionless.', $attachment->post_content );
|
||||
$this->assertEquals( 'Alt text is stored outside post schema.', $data['alt_text'] );
|
||||
$this->assertEquals( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );
|
||||
$this->assertSame( 'My title is very cool', $data['title']['raw'] );
|
||||
$this->assertSame( 'My title is very cool', $attachment->post_title );
|
||||
$this->assertSame( 'This is a better caption.', $data['caption']['raw'] );
|
||||
$this->assertSame( 'This is a better caption.', $attachment->post_excerpt );
|
||||
$this->assertSame( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );
|
||||
$this->assertSame( 'Without a description, my attachment is descriptionless.', $attachment->post_content );
|
||||
$this->assertSame( 'Alt text is stored outside post schema.', $data['alt_text'] );
|
||||
$this->assertSame( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );
|
||||
}
|
||||
|
||||
public function test_create_item_default_filename_title() {
|
||||
@@ -728,9 +728,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
);
|
||||
$request->set_header( 'Content-MD5', md5_file( $this->test_file2 ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 'codeispoetry', $data['title']['raw'] );
|
||||
$this->assertSame( 'codeispoetry', $data['title']['raw'] );
|
||||
}
|
||||
|
||||
public function test_create_item_with_files() {
|
||||
@@ -748,7 +748,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
);
|
||||
$request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
}
|
||||
|
||||
public function test_create_item_with_upload_files_role() {
|
||||
@@ -766,7 +766,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
);
|
||||
$request->set_header( 'Content-MD5', md5_file( $this->test_file ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
}
|
||||
|
||||
public function test_create_item_empty_body() {
|
||||
@@ -875,7 +875,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( 'alt_text', 'test alt text' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$attachment = $response->get_data();
|
||||
$this->assertEquals( 'test alt text', $attachment['alt_text'] );
|
||||
$this->assertSame( 'test alt text', $attachment['alt_text'] );
|
||||
}
|
||||
|
||||
public function test_create_item_unsafe_alt_text() {
|
||||
@@ -887,7 +887,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( 'alt_text', '<script>alert(document.cookie)</script>' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$attachment = $response->get_data();
|
||||
$this->assertEquals( '', $attachment['alt_text'] );
|
||||
$this->assertSame( '', $attachment['alt_text'] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -923,14 +923,14 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$attachment = get_post( $data['id'] );
|
||||
$this->assertEquals( 'My title is very cool', $data['title']['raw'] );
|
||||
$this->assertEquals( 'My title is very cool', $attachment->post_title );
|
||||
$this->assertEquals( 'This is a better caption.', $data['caption']['raw'] );
|
||||
$this->assertEquals( 'This is a better caption.', $attachment->post_excerpt );
|
||||
$this->assertEquals( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );
|
||||
$this->assertEquals( 'Without a description, my attachment is descriptionless.', $attachment->post_content );
|
||||
$this->assertEquals( 'Alt text is stored outside post schema.', $data['alt_text'] );
|
||||
$this->assertEquals( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );
|
||||
$this->assertSame( 'My title is very cool', $data['title']['raw'] );
|
||||
$this->assertSame( 'My title is very cool', $attachment->post_title );
|
||||
$this->assertSame( 'This is a better caption.', $data['caption']['raw'] );
|
||||
$this->assertSame( 'This is a better caption.', $attachment->post_excerpt );
|
||||
$this->assertSame( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );
|
||||
$this->assertSame( 'Without a description, my attachment is descriptionless.', $attachment->post_content );
|
||||
$this->assertSame( 'Alt text is stored outside post schema.', $data['alt_text'] );
|
||||
$this->assertSame( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );
|
||||
}
|
||||
|
||||
public function test_update_item_parent() {
|
||||
@@ -947,7 +947,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
);
|
||||
|
||||
$attachment = get_post( $attachment_id );
|
||||
$this->assertEquals( $original_parent, $attachment->post_parent );
|
||||
$this->assertSame( $original_parent, $attachment->post_parent );
|
||||
|
||||
$new_parent = $this->factory->post->create( array() );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/media/' . $attachment_id );
|
||||
@@ -955,7 +955,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
rest_get_server()->dispatch( $request );
|
||||
|
||||
$attachment = get_post( $attachment_id );
|
||||
$this->assertEquals( $new_parent, $attachment->post_parent );
|
||||
$this->assertSame( $new_parent, $attachment->post_parent );
|
||||
}
|
||||
|
||||
public function test_update_item_invalid_permissions() {
|
||||
@@ -1010,7 +1010,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( $name, $value );
|
||||
}
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$actual_output = $response->get_data();
|
||||
|
||||
// Remove <p class="attachment"> from rendered description.
|
||||
@@ -1023,18 +1023,18 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
}
|
||||
|
||||
// Compare expected API output to actual API output.
|
||||
$this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
|
||||
$this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
|
||||
$this->assertEquals( $expected_output['description']['raw'], $actual_output['description']['raw'] );
|
||||
$this->assertEquals( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );
|
||||
$this->assertEquals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );
|
||||
$this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['title']['raw'], $actual_output['title']['raw'] );
|
||||
$this->assertSame( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['description']['raw'], $actual_output['description']['raw'] );
|
||||
$this->assertSame( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );
|
||||
$this->assertSame( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
|
||||
|
||||
// Compare expected API output to WP internal values.
|
||||
$post = get_post( $actual_output['id'] );
|
||||
$this->assertEquals( $expected_output['title']['raw'], $post->post_title );
|
||||
$this->assertEquals( $expected_output['description']['raw'], $post->post_content );
|
||||
$this->assertEquals( $expected_output['caption']['raw'], $post->post_excerpt );
|
||||
$this->assertSame( $expected_output['title']['raw'], $post->post_title );
|
||||
$this->assertSame( $expected_output['description']['raw'], $post->post_content );
|
||||
$this->assertSame( $expected_output['caption']['raw'], $post->post_excerpt );
|
||||
|
||||
// Update the post.
|
||||
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/media/%d', $actual_output['id'] ) );
|
||||
@@ -1042,7 +1042,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( $name, $value );
|
||||
}
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$actual_output = $response->get_data();
|
||||
|
||||
// Remove <p class="attachment"> from rendered description.
|
||||
@@ -1055,18 +1055,18 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
}
|
||||
|
||||
// Compare expected API output to actual API output.
|
||||
$this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
|
||||
$this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
|
||||
$this->assertEquals( $expected_output['description']['raw'], $actual_output['description']['raw'] );
|
||||
$this->assertEquals( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );
|
||||
$this->assertEquals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );
|
||||
$this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['title']['raw'], $actual_output['title']['raw'] );
|
||||
$this->assertSame( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['description']['raw'], $actual_output['description']['raw'] );
|
||||
$this->assertSame( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );
|
||||
$this->assertSame( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );
|
||||
$this->assertSame( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
|
||||
|
||||
// Compare expected API output to WP internal values.
|
||||
$post = get_post( $actual_output['id'] );
|
||||
$this->assertEquals( $expected_output['title']['raw'], $post->post_title );
|
||||
$this->assertEquals( $expected_output['description']['raw'], $post->post_content );
|
||||
$this->assertEquals( $expected_output['caption']['raw'], $post->post_excerpt );
|
||||
$this->assertSame( $expected_output['title']['raw'], $post->post_title );
|
||||
$this->assertSame( $expected_output['description']['raw'], $post->post_content );
|
||||
$this->assertSame( $expected_output['caption']['raw'], $post->post_excerpt );
|
||||
}
|
||||
|
||||
public static function attachment_roundtrip_provider() {
|
||||
@@ -1265,7 +1265,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id );
|
||||
$request['force'] = true;
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
}
|
||||
|
||||
public function test_delete_item_no_trash() {
|
||||
@@ -1345,7 +1345,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_param( '_fields', 'id,slug' );
|
||||
$obj = get_post( $attachment_id );
|
||||
$response = $endpoint->prepare_item_for_response( $obj, $request );
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id',
|
||||
'slug',
|
||||
@@ -1359,7 +1359,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertEquals( 27, count( $properties ) );
|
||||
$this->assertSame( 27, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'author', $properties );
|
||||
$this->assertArrayHasKey( 'alt_text', $properties );
|
||||
$this->assertArrayHasKey( 'caption', $properties );
|
||||
@@ -1418,7 +1418,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
|
||||
$this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
|
||||
$this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
|
||||
|
||||
$attachment_id = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
@@ -1506,8 +1506,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertEquals( $id2, $data[0]['id'] );
|
||||
$this->assertEquals( 'image/png', $data[0]['mime_type'] );
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
$this->assertSame( 'image/png', $data[0]['mime_type'] );
|
||||
}
|
||||
|
||||
public function additional_field_get_callback( $object, $request ) {
|
||||
@@ -1575,10 +1575,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertArrayNotHasKey( 'content', $data );
|
||||
$this->assertArrayNotHasKey( 'excerpt', $data );
|
||||
|
||||
$this->assertEquals( get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), $data['alt_text'] );
|
||||
$this->assertSame( get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), $data['alt_text'] );
|
||||
if ( 'edit' === $context ) {
|
||||
$this->assertEquals( $attachment->post_excerpt, $data['caption']['raw'] );
|
||||
$this->assertEquals( $attachment->post_content, $data['description']['raw'] );
|
||||
$this->assertSame( $attachment->post_excerpt, $data['caption']['raw'] );
|
||||
$this->assertSame( $attachment->post_content, $data['description']['raw'] );
|
||||
} else {
|
||||
$this->assertFalse( isset( $data['caption']['raw'] ) );
|
||||
$this->assertFalse( isset( $data['description']['raw'] ) );
|
||||
@@ -1586,12 +1586,12 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertTrue( isset( $data['media_details'] ) );
|
||||
|
||||
if ( $attachment->post_parent ) {
|
||||
$this->assertEquals( $attachment->post_parent, $data['post'] );
|
||||
$this->assertSame( $attachment->post_parent, $data['post'] );
|
||||
} else {
|
||||
$this->assertNull( $data['post'] );
|
||||
}
|
||||
|
||||
$this->assertEquals( wp_get_attachment_url( $attachment->ID ), $data['source_url'] );
|
||||
$this->assertSame( wp_get_attachment_url( $attachment->ID ), $data['source_url'] );
|
||||
|
||||
}
|
||||
|
||||
@@ -1721,7 +1721,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$request->set_body( file_get_contents( $this->test_file ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
|
||||
$this->assertSame( 1, self::$rest_insert_attachment_count );
|
||||
$this->assertSame( 1, self::$rest_after_insert_attachment_count );
|
||||
@@ -1782,8 +1782,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertEquals( 'Chocolate-dipped, no filling', get_post_meta( $response->get_data()['id'], 'best_cannoli', true ) );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertSame( 'Chocolate-dipped, no filling', get_post_meta( $response->get_data()['id'], 'best_cannoli', true ) );
|
||||
}
|
||||
|
||||
public function filter_rest_insert_attachment( $attachment ) {
|
||||
@@ -1901,7 +1901,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertErrorResponse( 'rest_image_rotation_failed', $response, 500 );
|
||||
|
||||
$this->assertCount( 1, WP_Image_Editor_Mock::$spy['rotate'] );
|
||||
$this->assertEquals( array( -60 ), WP_Image_Editor_Mock::$spy['rotate'][0] );
|
||||
$this->assertSame( array( -60 ), WP_Image_Editor_Mock::$spy['rotate'][0] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1934,7 +1934,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertErrorResponse( 'rest_image_crop_failed', $response, 500 );
|
||||
|
||||
$this->assertCount( 1, WP_Image_Editor_Mock::$spy['crop'] );
|
||||
$this->assertEquals(
|
||||
$this->assertSame(
|
||||
array( 320.0, 48.0, 64.0, 24.0 ),
|
||||
WP_Image_Editor_Mock::$spy['crop'][0]
|
||||
);
|
||||
@@ -1957,8 +1957,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$response = rest_do_request( $request );
|
||||
$item = $response->get_data();
|
||||
|
||||
$this->assertEquals( 201, $response->get_status() );
|
||||
$this->assertEquals( rest_url( '/wp/v2/media/' . $item['id'] ), $response->get_headers()['Location'] );
|
||||
$this->assertSame( 201, $response->get_status() );
|
||||
$this->assertSame( rest_url( '/wp/v2/media/' . $item['id'] ), $response->get_headers()['Location'] );
|
||||
|
||||
$this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] );
|
||||
$this->assertArrayHasKey( 'parent_image', $item['media_details'] );
|
||||
|
||||
Reference in New Issue
Block a user