- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r48794 r48937 156 156 $header_list = array( $header ); 157 157 $parsed = WP_REST_Attachments_Controller::get_filename_from_disposition( $header_list ); 158 $this->assert Equals( $expected, $parsed );158 $this->assertSame( $expected, $parsed ); 159 159 } 160 160 … … 164 164 $response = rest_get_server()->dispatch( $request ); 165 165 $data = $response->get_data(); 166 $this->assert Equals( 'view', $data['endpoints'][0]['args']['context']['default'] );167 $this->assert Equals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );166 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 167 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 168 168 // Single. 169 169 $attachment_id = $this->factory->attachment->create_object( … … 178 178 $response = rest_get_server()->dispatch( $request ); 179 179 $data = $response->get_data(); 180 $this->assert Equals( 'view', $data['endpoints'][0]['args']['context']['default'] );181 $this->assert Equals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );180 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 181 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 182 182 } 183 183 … … 188 188 $keys = array_keys( $data['endpoints'][0]['args'] ); 189 189 sort( $keys ); 190 $this->assert Equals(190 $this->assertSame( 191 191 array( 192 192 'after', … … 238 238 $keys = array_keys( $data['endpoints'][0]['args'] ); 239 239 sort( $keys ); 240 $this->assert Equals( array( 'context', 'id' ), $keys );240 $this->assertSame( array( 'context', 'id' ), $keys ); 241 241 } 242 242 … … 259 259 260 260 $this->assertNotEmpty( $headers['Allow'] ); 261 $this->assert Equals( $headers['Allow'], 'GET' );261 $this->assertSame( $headers['Allow'], 'GET' ); 262 262 263 263 wp_set_current_user( self::$editor_id ); … … 268 268 269 269 $this->assertNotEmpty( $headers['Allow'] ); 270 $this->assert Equals( $headers['Allow'], 'GET, POST, PUT, PATCH, DELETE' );270 $this->assertSame( $headers['Allow'], 'GET, POST, PUT, PATCH, DELETE' ); 271 271 } 272 272 … … 361 361 $response = rest_get_server()->dispatch( $request ); 362 362 $data = $response->get_data(); 363 $this->assert Equals( $id1, $data[0]['id'] );363 $this->assertSame( $id1, $data[0]['id'] ); 364 364 // 'media_type' => 'video'. 365 365 $request->set_param( 'media_type', 'video' ); … … 370 370 $response = rest_get_server()->dispatch( $request ); 371 371 $data = $response->get_data(); 372 $this->assert Equals( $id1, $data[0]['id'] );372 $this->assertSame( $id1, $data[0]['id'] ); 373 373 } 374 374 … … 384 384 $response = rest_get_server()->dispatch( $request ); 385 385 $data = $response->get_data(); 386 $this->assert Equals( $id1, $data[0]['id'] );386 $this->assertSame( $id1, $data[0]['id'] ); 387 387 // 'mime_type' => 'image/png'. 388 388 $request->set_param( 'mime_type', 'image/png' ); … … 393 393 $response = rest_get_server()->dispatch( $request ); 394 394 $data = $response->get_data(); 395 $this->assert Equals( $id1, $data[0]['id'] );395 $this->assertSame( $id1, $data[0]['id'] ); 396 396 } 397 397 … … 417 417 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 418 418 $response = rest_get_server()->dispatch( $request ); 419 $this->assert Equals( 2, count( $response->get_data() ) );419 $this->assertSame( 2, count( $response->get_data() ) ); 420 420 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 421 421 // Attachments without a parent. … … 423 423 $response = rest_get_server()->dispatch( $request ); 424 424 $data = $response->get_data(); 425 $this->assert Equals( 1, count( $data ) );426 $this->assert Equals( $attachment_id2, $data[0]['id'] );425 $this->assertSame( 1, count( $data ) ); 426 $this->assertSame( $attachment_id2, $data[0]['id'] ); 427 427 // Attachments with parent=post_id. 428 428 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); … … 430 430 $response = rest_get_server()->dispatch( $request ); 431 431 $data = $response->get_data(); 432 $this->assert Equals( 1, count( $data ) );433 $this->assert Equals( $attachment_id, $data[0]['id'] );432 $this->assertSame( 1, count( $data ) ); 433 $this->assertSame( $attachment_id, $data[0]['id'] ); 434 434 // Attachments with invalid parent. 435 435 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); … … 437 437 $response = rest_get_server()->dispatch( $request ); 438 438 $data = $response->get_data(); 439 $this->assert Equals( 0, count( $data ) );439 $this->assertSame( 0, count( $data ) ); 440 440 } 441 441 … … 456 456 $data = $response->get_data(); 457 457 $this->assertCount( 3, $data ); 458 $this->assert Equals( 'rest_invalid_param', $data['code'] );458 $this->assertSame( 'rest_invalid_param', $data['code'] ); 459 459 } 460 460 … … 478 478 wp_set_current_user( self::$editor_id ); 479 479 $response = rest_get_server()->dispatch( $request ); 480 $this->assert Equals( 200, $response->get_status() );480 $this->assertSame( 200, $response->get_status() ); 481 481 $data = $response->get_data(); 482 $this->assert Equals( $attachment_id1, $data[0]['id'] );482 $this->assertSame( $attachment_id1, $data[0]['id'] ); 483 483 } 484 484 … … 511 511 wp_set_current_user( self::$editor_id ); 512 512 $response = rest_get_server()->dispatch( $request ); 513 $this->assert Equals( 200, $response->get_status() );513 $this->assertSame( 200, $response->get_status() ); 514 514 $data = $response->get_data(); 515 $this->assert Equals( 2, count( $data ) );515 $this->assertSame( 2, count( $data ) ); 516 516 $ids = array( 517 517 $data[0]['id'], … … 519 519 ); 520 520 sort( $ids ); 521 $this->assert Equals( array( $attachment_id1, $attachment_id2 ), $ids );521 $this->assertSame( array( $attachment_id1, $attachment_id2 ), $ids ); 522 522 } 523 523 … … 564 564 $data = $response->get_data(); 565 565 $this->assertCount( 1, $data ); 566 $this->assert Equals( $id2, $data[0]['id'] );566 $this->assertSame( $id2, $data[0]['id'] ); 567 567 } 568 568 … … 581 581 $this->check_get_post_response( $response ); 582 582 $data = $response->get_data(); 583 $this->assert Equals( 'image/jpeg', $data['mime_type'] );583 $this->assertSame( 'image/jpeg', $data['mime_type'] ); 584 584 } 585 585 … … 605 605 remove_image_size( 'rest-api-test' ); 606 606 607 $this->assert Equals( $image_src[0], $data['media_details']['sizes']['rest-api-test']['source_url'] );608 $this->assert Equals( 'image/jpeg', $data['media_details']['sizes']['rest-api-test']['mime_type'] );609 $this->assert Equals( $original_image_src[0], $data['media_details']['sizes']['full']['source_url'] );610 $this->assert Equals( 'image/jpeg', $data['media_details']['sizes']['full']['mime_type'] );607 $this->assertSame( $image_src[0], $data['media_details']['sizes']['rest-api-test']['source_url'] ); 608 $this->assertSame( 'image/jpeg', $data['media_details']['sizes']['rest-api-test']['mime_type'] ); 609 $this->assertSame( $original_image_src[0], $data['media_details']['sizes']['full']['source_url'] ); 610 $this->assertSame( 'image/jpeg', $data['media_details']['sizes']['full']['mime_type'] ); 611 611 } 612 612 … … 649 649 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $id1 ); 650 650 $response = rest_get_server()->dispatch( $request ); 651 $this->assert Equals( 401, $response->get_status() );651 $this->assertSame( 401, $response->get_status() ); 652 652 } 653 653 … … 665 665 $data = $response->get_data(); 666 666 667 $this->assert Equals( 200, $response->get_status() );668 $this->assert Equals( $attachment_id, $data['id'] );667 $this->assertSame( 200, $response->get_status() ); 668 $this->assertSame( $attachment_id, $data['id'] ); 669 669 } 670 670 … … 700 700 $data = $response->get_data(); 701 701 702 $this->assert Equals( 201, $response->get_status() );703 $this->assert Equals( 'image', $data['media_type'] );702 $this->assertSame( 201, $response->get_status() ); 703 $this->assertSame( 'image', $data['media_type'] ); 704 704 705 705 $attachment = get_post( $data['id'] ); 706 $this->assert Equals( 'My title is very cool', $data['title']['raw'] );707 $this->assert Equals( 'My title is very cool', $attachment->post_title );708 $this->assert Equals( 'This is a better caption.', $data['caption']['raw'] );709 $this->assert Equals( 'This is a better caption.', $attachment->post_excerpt );710 $this->assert Equals( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );711 $this->assert Equals( 'Without a description, my attachment is descriptionless.', $attachment->post_content );712 $this->assert Equals( 'Alt text is stored outside post schema.', $data['alt_text'] );713 $this->assert Equals( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );706 $this->assertSame( 'My title is very cool', $data['title']['raw'] ); 707 $this->assertSame( 'My title is very cool', $attachment->post_title ); 708 $this->assertSame( 'This is a better caption.', $data['caption']['raw'] ); 709 $this->assertSame( 'This is a better caption.', $attachment->post_excerpt ); 710 $this->assertSame( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] ); 711 $this->assertSame( 'Without a description, my attachment is descriptionless.', $attachment->post_content ); 712 $this->assertSame( 'Alt text is stored outside post schema.', $data['alt_text'] ); 713 $this->assertSame( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) ); 714 714 } 715 715 … … 729 729 $request->set_header( 'Content-MD5', md5_file( $this->test_file2 ) ); 730 730 $response = rest_get_server()->dispatch( $request ); 731 $this->assert Equals( 201, $response->get_status() );731 $this->assertSame( 201, $response->get_status() ); 732 732 $data = $response->get_data(); 733 $this->assert Equals( 'codeispoetry', $data['title']['raw'] );733 $this->assertSame( 'codeispoetry', $data['title']['raw'] ); 734 734 } 735 735 … … 749 749 $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); 750 750 $response = rest_get_server()->dispatch( $request ); 751 $this->assert Equals( 201, $response->get_status() );751 $this->assertSame( 201, $response->get_status() ); 752 752 } 753 753 … … 767 767 $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); 768 768 $response = rest_get_server()->dispatch( $request ); 769 $this->assert Equals( 201, $response->get_status() );769 $this->assertSame( 201, $response->get_status() ); 770 770 } 771 771 … … 876 876 $response = rest_get_server()->dispatch( $request ); 877 877 $attachment = $response->get_data(); 878 $this->assert Equals( 'test alt text', $attachment['alt_text'] );878 $this->assertSame( 'test alt text', $attachment['alt_text'] ); 879 879 } 880 880 … … 888 888 $response = rest_get_server()->dispatch( $request ); 889 889 $attachment = $response->get_data(); 890 $this->assert Equals( '', $attachment['alt_text'] );890 $this->assertSame( '', $attachment['alt_text'] ); 891 891 } 892 892 … … 924 924 $data = $response->get_data(); 925 925 $attachment = get_post( $data['id'] ); 926 $this->assert Equals( 'My title is very cool', $data['title']['raw'] );927 $this->assert Equals( 'My title is very cool', $attachment->post_title );928 $this->assert Equals( 'This is a better caption.', $data['caption']['raw'] );929 $this->assert Equals( 'This is a better caption.', $attachment->post_excerpt );930 $this->assert Equals( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] );931 $this->assert Equals( 'Without a description, my attachment is descriptionless.', $attachment->post_content );932 $this->assert Equals( 'Alt text is stored outside post schema.', $data['alt_text'] );933 $this->assert Equals( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) );926 $this->assertSame( 'My title is very cool', $data['title']['raw'] ); 927 $this->assertSame( 'My title is very cool', $attachment->post_title ); 928 $this->assertSame( 'This is a better caption.', $data['caption']['raw'] ); 929 $this->assertSame( 'This is a better caption.', $attachment->post_excerpt ); 930 $this->assertSame( 'Without a description, my attachment is descriptionless.', $data['description']['raw'] ); 931 $this->assertSame( 'Without a description, my attachment is descriptionless.', $attachment->post_content ); 932 $this->assertSame( 'Alt text is stored outside post schema.', $data['alt_text'] ); 933 $this->assertSame( 'Alt text is stored outside post schema.', get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ) ); 934 934 } 935 935 … … 948 948 949 949 $attachment = get_post( $attachment_id ); 950 $this->assert Equals( $original_parent, $attachment->post_parent );950 $this->assertSame( $original_parent, $attachment->post_parent ); 951 951 952 952 $new_parent = $this->factory->post->create( array() ); … … 956 956 957 957 $attachment = get_post( $attachment_id ); 958 $this->assert Equals( $new_parent, $attachment->post_parent );958 $this->assertSame( $new_parent, $attachment->post_parent ); 959 959 } 960 960 … … 1011 1011 } 1012 1012 $response = rest_get_server()->dispatch( $request ); 1013 $this->assert Equals( 201, $response->get_status() );1013 $this->assertSame( 201, $response->get_status() ); 1014 1014 $actual_output = $response->get_data(); 1015 1015 … … 1024 1024 1025 1025 // Compare expected API output to actual API output. 1026 $this->assert Equals( $expected_output['title']['raw'], $actual_output['title']['raw'] );1027 $this->assert Equals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );1028 $this->assert Equals( $expected_output['description']['raw'], $actual_output['description']['raw'] );1029 $this->assert Equals( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );1030 $this->assert Equals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );1031 $this->assert Equals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );1026 $this->assertSame( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 1027 $this->assertSame( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); 1028 $this->assertSame( $expected_output['description']['raw'], $actual_output['description']['raw'] ); 1029 $this->assertSame( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) ); 1030 $this->assertSame( $expected_output['caption']['raw'], $actual_output['caption']['raw'] ); 1031 $this->assertSame( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); 1032 1032 1033 1033 // Compare expected API output to WP internal values. 1034 1034 $post = get_post( $actual_output['id'] ); 1035 $this->assert Equals( $expected_output['title']['raw'], $post->post_title );1036 $this->assert Equals( $expected_output['description']['raw'], $post->post_content );1037 $this->assert Equals( $expected_output['caption']['raw'], $post->post_excerpt );1035 $this->assertSame( $expected_output['title']['raw'], $post->post_title ); 1036 $this->assertSame( $expected_output['description']['raw'], $post->post_content ); 1037 $this->assertSame( $expected_output['caption']['raw'], $post->post_excerpt ); 1038 1038 1039 1039 // Update the post. … … 1043 1043 } 1044 1044 $response = rest_get_server()->dispatch( $request ); 1045 $this->assert Equals( 200, $response->get_status() );1045 $this->assertSame( 200, $response->get_status() ); 1046 1046 $actual_output = $response->get_data(); 1047 1047 … … 1056 1056 1057 1057 // Compare expected API output to actual API output. 1058 $this->assert Equals( $expected_output['title']['raw'], $actual_output['title']['raw'] );1059 $this->assert Equals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );1060 $this->assert Equals( $expected_output['description']['raw'], $actual_output['description']['raw'] );1061 $this->assert Equals( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) );1062 $this->assert Equals( $expected_output['caption']['raw'], $actual_output['caption']['raw'] );1063 $this->assert Equals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );1058 $this->assertSame( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 1059 $this->assertSame( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); 1060 $this->assertSame( $expected_output['description']['raw'], $actual_output['description']['raw'] ); 1061 $this->assertSame( $expected_output['description']['rendered'], trim( $actual_output['description']['rendered'] ) ); 1062 $this->assertSame( $expected_output['caption']['raw'], $actual_output['caption']['raw'] ); 1063 $this->assertSame( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) ); 1064 1064 1065 1065 // Compare expected API output to WP internal values. 1066 1066 $post = get_post( $actual_output['id'] ); 1067 $this->assert Equals( $expected_output['title']['raw'], $post->post_title );1068 $this->assert Equals( $expected_output['description']['raw'], $post->post_content );1069 $this->assert Equals( $expected_output['caption']['raw'], $post->post_excerpt );1067 $this->assertSame( $expected_output['title']['raw'], $post->post_title ); 1068 $this->assertSame( $expected_output['description']['raw'], $post->post_content ); 1069 $this->assertSame( $expected_output['caption']['raw'], $post->post_excerpt ); 1070 1070 } 1071 1071 … … 1266 1266 $request['force'] = true; 1267 1267 $response = rest_get_server()->dispatch( $request ); 1268 $this->assert Equals( 200, $response->get_status() );1268 $this->assertSame( 200, $response->get_status() ); 1269 1269 } 1270 1270 … … 1346 1346 $obj = get_post( $attachment_id ); 1347 1347 $response = $endpoint->prepare_item_for_response( $obj, $request ); 1348 $this->assert Equals(1348 $this->assertSame( 1349 1349 array( 1350 1350 'id', … … 1360 1360 $data = $response->get_data(); 1361 1361 $properties = $data['schema']['properties']; 1362 $this->assert Equals( 27, count( $properties ) );1362 $this->assertSame( 27, count( $properties ) ); 1363 1363 $this->assertArrayHasKey( 'author', $properties ); 1364 1364 $this->assertArrayHasKey( 'alt_text', $properties ); … … 1419 1419 $data = $response->get_data(); 1420 1420 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); 1421 $this->assert Equals( $schema, $data['schema']['properties']['my_custom_int'] );1421 $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] ); 1422 1422 1423 1423 $attachment_id = $this->factory->attachment->create_object( … … 1507 1507 1508 1508 $this->assertCount( 1, $data ); 1509 $this->assert Equals( $id2, $data[0]['id'] );1510 $this->assert Equals( 'image/png', $data[0]['mime_type'] );1509 $this->assertSame( $id2, $data[0]['id'] ); 1510 $this->assertSame( 'image/png', $data[0]['mime_type'] ); 1511 1511 } 1512 1512 … … 1576 1576 $this->assertArrayNotHasKey( 'excerpt', $data ); 1577 1577 1578 $this->assert Equals( get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), $data['alt_text'] );1578 $this->assertSame( get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), $data['alt_text'] ); 1579 1579 if ( 'edit' === $context ) { 1580 $this->assert Equals( $attachment->post_excerpt, $data['caption']['raw'] );1581 $this->assert Equals( $attachment->post_content, $data['description']['raw'] );1580 $this->assertSame( $attachment->post_excerpt, $data['caption']['raw'] ); 1581 $this->assertSame( $attachment->post_content, $data['description']['raw'] ); 1582 1582 } else { 1583 1583 $this->assertFalse( isset( $data['caption']['raw'] ) ); … … 1587 1587 1588 1588 if ( $attachment->post_parent ) { 1589 $this->assert Equals( $attachment->post_parent, $data['post'] );1589 $this->assertSame( $attachment->post_parent, $data['post'] ); 1590 1590 } else { 1591 1591 $this->assertNull( $data['post'] ); 1592 1592 } 1593 1593 1594 $this->assert Equals( wp_get_attachment_url( $attachment->ID ), $data['source_url'] );1594 $this->assertSame( wp_get_attachment_url( $attachment->ID ), $data['source_url'] ); 1595 1595 1596 1596 } … … 1722 1722 $response = rest_get_server()->dispatch( $request ); 1723 1723 $data = $response->get_data(); 1724 $this->assert Equals( 201, $response->get_status() );1724 $this->assertSame( 201, $response->get_status() ); 1725 1725 1726 1726 $this->assertSame( 1, self::$rest_insert_attachment_count ); … … 1783 1783 $data = $response->get_data(); 1784 1784 1785 $this->assert Equals( 201, $response->get_status() );1786 $this->assert Equals( 'Chocolate-dipped, no filling', get_post_meta( $response->get_data()['id'], 'best_cannoli', true ) );1785 $this->assertSame( 201, $response->get_status() ); 1786 $this->assertSame( 'Chocolate-dipped, no filling', get_post_meta( $response->get_data()['id'], 'best_cannoli', true ) ); 1787 1787 } 1788 1788 … … 1902 1902 1903 1903 $this->assertCount( 1, WP_Image_Editor_Mock::$spy['rotate'] ); 1904 $this->assert Equals( array( -60 ), WP_Image_Editor_Mock::$spy['rotate'][0] );1904 $this->assertSame( array( -60 ), WP_Image_Editor_Mock::$spy['rotate'][0] ); 1905 1905 } 1906 1906 … … 1935 1935 1936 1936 $this->assertCount( 1, WP_Image_Editor_Mock::$spy['crop'] ); 1937 $this->assert Equals(1937 $this->assertSame( 1938 1938 array( 320.0, 48.0, 64.0, 24.0 ), 1939 1939 WP_Image_Editor_Mock::$spy['crop'][0] … … 1958 1958 $item = $response->get_data(); 1959 1959 1960 $this->assert Equals( 201, $response->get_status() );1961 $this->assert Equals( rest_url( '/wp/v2/media/' . $item['id'] ), $response->get_headers()['Location'] );1960 $this->assertSame( 201, $response->get_status() ); 1961 $this->assertSame( rest_url( '/wp/v2/media/' . $item['id'] ), $response->get_headers()['Location'] ); 1962 1962 1963 1963 $this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] );
Note: See TracChangeset
for help on using the changeset viewer.