- Timestamp:
- 01/19/2023 09:46:58 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r54428 r55102 1679 1679 } 1680 1680 1681 public function test_search_item_by_filename() { 1682 $id1 = self::factory()->attachment->create_object( 1683 self::$test_file, 1684 0, 1685 array( 1686 'post_mime_type' => 'image/jpeg', 1687 ) 1688 ); 1689 $id2 = self::factory()->attachment->create_object( 1690 self::$test_file2, 1691 0, 1692 array( 1693 'post_mime_type' => 'image/png', 1694 ) 1695 ); 1696 1697 $filename = wp_basename( self::$test_file2 ); 1698 1699 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 1700 $request->set_param( 'search', $filename ); 1701 $response = rest_get_server()->dispatch( $request ); 1702 $data = $response->get_data(); 1703 1704 $this->assertCount( 1, $data ); 1705 $this->assertSame( $id2, $data[0]['id'] ); 1706 $this->assertSame( 'image/png', $data[0]['mime_type'] ); 1707 } 1708 1709 public function additional_field_get_callback( $object, $request ) { 1681 public function additional_field_get_callback( $object, $field_name ) { 1710 1682 return 123; 1711 1683 } … … 1715 1687 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 1716 1688 } 1689 } 1690 1691 public function test_search_item_by_filename() { 1692 $id1 = self::factory()->attachment->create_object( 1693 self::$test_file, 1694 0, 1695 array( 1696 'post_mime_type' => 'image/jpeg', 1697 ) 1698 ); 1699 $id2 = self::factory()->attachment->create_object( 1700 self::$test_file2, 1701 0, 1702 array( 1703 'post_mime_type' => 'image/png', 1704 ) 1705 ); 1706 1707 $filename = wp_basename( self::$test_file2 ); 1708 1709 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 1710 $request->set_param( 'search', $filename ); 1711 $response = rest_get_server()->dispatch( $request ); 1712 $data = $response->get_data(); 1713 1714 $this->assertCount( 1, $data ); 1715 $this->assertSame( $id2, $data[0]['id'] ); 1716 $this->assertSame( 'image/png', $data[0]['mime_type'] ); 1717 1717 } 1718 1718
Note: See TracChangeset
for help on using the changeset viewer.