Make WordPress Core

Ticket #39092: 39092-test.diff

File 39092-test.diff, 1.1 KB (added by tyxla, 10 years ago)

Add test for searching media by filename in the media REST API endpoint

  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

     
    11431143                $wp_rest_additional_fields = array();
    11441144        }
    11451145
     1146        public function test_search_item_by_filename() {
     1147                $this->factory->attachment->create_object( $this->test_file, 0, array(
     1148                        'post_mime_type' => 'image/jpeg',
     1149                ) );
     1150                $this->factory->attachment->create_object( $this->test_file2, 0, array(
     1151                        'post_mime_type' => 'image/png',
     1152                ) );
     1153
     1154                $filename = basename( $this->test_file2 );
     1155
     1156                $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
     1157                $request->set_param( 'search', $filename );
     1158                $response = $this->server->dispatch( $request );
     1159                $data = $response->get_data();
     1160
     1161                $this->assertCount( 1, $data );
     1162                $this->assertArrayHasKey( 0, $data );
     1163                $this->assertEquals( 'image/png', $data[0]['mime_type'] );
     1164        }
     1165
    11461166        public function additional_field_get_callback( $object, $request ) {
    11471167                return 123;
    11481168        }