- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php
r42228 r42343 20 20 public function test_context_param() { 21 21 // Collection 22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );23 $response = $this->server->dispatch( $request ); 24 $data = $response->get_data();22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); 23 $response = $this->server->dispatch( $request ); 24 $data = $response->get_data(); 25 25 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 26 26 $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); 27 27 // Single 28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' );29 $response = $this->server->dispatch( $request ); 30 $data = $response->get_data();28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/post' ); 29 $response = $this->server->dispatch( $request ); 30 $data = $response->get_data(); 31 31 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 32 32 $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 34 34 35 35 public function test_get_items() { 36 $request = new WP_REST_Request( 'GET', '/wp/v2/types' );37 $response = $this->server->dispatch( $request ); 38 39 $data = $response->get_data();36 $request = new WP_REST_Request( 'GET', '/wp/v2/types' ); 37 $response = $this->server->dispatch( $request ); 38 39 $data = $response->get_data(); 40 40 $post_types = get_post_types( array( 'show_in_rest' => true ), 'objects' ); 41 41 $this->assertEquals( count( $post_types ), count( $data ) ); … … 56 56 57 57 public function test_get_item() { 58 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' );58 $request = new WP_REST_Request( 'GET', '/wp/v2/types/post' ); 59 59 $response = $this->server->dispatch( $request ); 60 60 $this->check_post_type_object_response( 'view', $response ); … … 64 64 65 65 public function test_get_item_page() { 66 $request = new WP_REST_Request( 'GET', '/wp/v2/types/page' );66 $request = new WP_REST_Request( 'GET', '/wp/v2/types/page' ); 67 67 $response = $this->server->dispatch( $request ); 68 68 $this->check_post_type_object_response( 'view', $response, 'page' ); … … 72 72 73 73 public function test_get_item_invalid_type() { 74 $request = new WP_REST_Request( 'GET', '/wp/v2/types/invalid' );74 $request = new WP_REST_Request( 'GET', '/wp/v2/types/invalid' ); 75 75 $response = $this->server->dispatch( $request ); 76 76 $this->assertErrorResponse( 'rest_type_invalid', $response, 404 ); … … 95 95 96 96 public function test_create_item() { 97 /** Post types can't be created * */98 $request = new WP_REST_Request( 'POST', '/wp/v2/types' );97 /** Post types can't be created */ 98 $request = new WP_REST_Request( 'POST', '/wp/v2/types' ); 99 99 $response = $this->server->dispatch( $request ); 100 100 $this->assertEquals( 404, $response->get_status() ); … … 102 102 103 103 public function test_update_item() { 104 /** Post types can't be updated * */105 $request = new WP_REST_Request( 'POST', '/wp/v2/types/post' );104 /** Post types can't be updated */ 105 $request = new WP_REST_Request( 'POST', '/wp/v2/types/post' ); 106 106 $response = $this->server->dispatch( $request ); 107 107 $this->assertEquals( 404, $response->get_status() ); … … 109 109 110 110 public function test_delete_item() { 111 /** Post types can't be deleted * */112 $request = new WP_REST_Request( 'DELETE', '/wp/v2/types/post' );111 /** Post types can't be deleted */ 112 $request = new WP_REST_Request( 'DELETE', '/wp/v2/types/post' ); 113 113 $response = $this->server->dispatch( $request ); 114 114 $this->assertEquals( 404, $response->get_status() ); … … 116 116 117 117 public function test_prepare_item() { 118 $obj = get_post_type_object( 'post' );118 $obj = get_post_type_object( 'post' ); 119 119 $endpoint = new WP_REST_Post_Types_Controller; 120 $request = new WP_REST_Request;120 $request = new WP_REST_Request; 121 121 $request->set_param( 'context', 'edit' ); 122 122 $response = $endpoint->prepare_item_for_response( $obj, $request ); … … 125 125 126 126 public function test_get_item_schema() { 127 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' );128 $response = $this->server->dispatch( $request );129 $data = $response->get_data();127 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); 128 $response = $this->server->dispatch( $request ); 129 $data = $response->get_data(); 130 130 $properties = $data['schema']['properties']; 131 131 $this->assertEquals( 9, count( $properties ) ); … … 150 150 ); 151 151 152 register_rest_field( 'type', 'my_custom_int', array( 153 'schema' => $schema, 154 'get_callback' => array( $this, 'additional_field_get_callback' ), 155 'update_callback' => array( $this, 'additional_field_update_callback' ), 156 ) ); 152 register_rest_field( 153 'type', 'my_custom_int', array( 154 'schema' => $schema, 155 'get_callback' => array( $this, 'additional_field_get_callback' ), 156 'update_callback' => array( $this, 'additional_field_update_callback' ), 157 ) 158 ); 157 159 158 160 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types/schema' ); 159 161 160 162 $response = $this->server->dispatch( $request ); 161 $data = $response->get_data();163 $data = $response->get_data(); 162 164 163 165 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 201 203 $this->assertEquals( 200, $response->get_status() ); 202 204 $data = $response->get_data(); 203 $obj = get_post_type_object( $post_type );205 $obj = get_post_type_object( $post_type ); 204 206 $this->check_post_type_obj( $context, $obj, $data, $response->get_links() ); 205 207 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)