- Timestamp:
- 11/30/2021 12:22:30 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php
r52186 r52275 54 54 } 55 55 56 57 56 public function test_register_routes() { 58 57 $routes = rest_get_server()->get_routes(); … … 94 93 'slug' => 'my_template', 95 94 'source' => 'custom', 95 'origin' => null, 96 96 'type' => 'wp_template', 97 97 'description' => 'Description of my template.', … … 103 103 'wp_id' => self::$post->ID, 104 104 'has_theme_file' => false, 105 'is_custom' => true, 106 'author' => 0, 105 107 ), 106 108 $this->find_and_normalize_template_by_id( $data, 'default//my_template' ) … … 135 137 'slug' => 'my_template', 136 138 'source' => 'custom', 139 'origin' => null, 137 140 'type' => 'wp_template', 138 141 'description' => 'Description of my template.', … … 144 147 'wp_id' => self::$post->ID, 145 148 'has_theme_file' => false, 149 'is_custom' => true, 150 'author' => 0, 146 151 ), 147 152 $data 153 ); 154 } 155 156 /** 157 * @ticket 54507 158 * @dataProvider get_template_endpoint_urls 159 */ 160 public function test_get_item_works_with_a_single_slash( $endpoint_url ) { 161 wp_set_current_user( self::$admin_id ); 162 $request = new WP_REST_Request( 'GET', $endpoint_url ); 163 $response = rest_get_server()->dispatch( $request ); 164 165 $data = $response->get_data(); 166 unset( $data['content'] ); 167 unset( $data['_links'] ); 168 169 $this->assertSame( 170 array( 171 'id' => 'default//my_template', 172 'theme' => 'default', 173 'slug' => 'my_template', 174 'source' => 'custom', 175 'origin' => null, 176 'type' => 'wp_template', 177 'description' => 'Description of my template.', 178 'title' => array( 179 'raw' => 'My Template', 180 'rendered' => 'My Template', 181 ), 182 'status' => 'publish', 183 'wp_id' => self::$post->ID, 184 'has_theme_file' => false, 185 'is_custom' => true, 186 'author' => 0, 187 ), 188 $data 189 ); 190 } 191 192 public function get_template_endpoint_urls() { 193 return array( 194 array( '/wp/v2/templates/default/my_template' ), 195 array( '/wp/v2/templates/default//my_template' ), 196 ); 197 } 198 199 /** 200 * @ticket 54507 201 * @dataProvider get_template_ids_to_sanitize 202 */ 203 public function test_sanitize_template_id( $input_id, $sanitized_id ) { 204 $endpoint = new WP_REST_Templates_Controller( 'wp_template' ); 205 $this->assertEquals( 206 $sanitized_id, 207 $endpoint->_sanitize_template_id( $input_id ) 208 ); 209 } 210 211 public function get_template_ids_to_sanitize() { 212 return array( 213 array( 'tt1-blocks/index', 'tt1-blocks//index' ), 214 array( 'tt1-blocks//index', 'tt1-blocks//index' ), 215 216 array( 'theme-experiments/tt1-blocks/index', 'theme-experiments/tt1-blocks//index' ), 217 array( 'theme-experiments/tt1-blocks//index', 'theme-experiments/tt1-blocks//index' ), 148 218 ); 149 219 } … … 162 232 'title' => 'My Template', 163 233 'content' => 'Content', 234 'author' => self::$admin_id, 164 235 ) 165 236 ); … … 178 249 'slug' => 'my_custom_template', 179 250 'source' => 'custom', 251 'origin' => null, 180 252 'type' => 'wp_template', 181 253 'description' => 'Just a description', … … 186 258 'status' => 'publish', 187 259 'has_theme_file' => false, 260 'is_custom' => true, 261 'author' => self::$admin_id, 188 262 ), 189 263 $data … … 208 282 'raw' => 'Content', 209 283 ), 284 'author' => self::$admin_id, 210 285 ) 211 286 ); … … 224 299 'slug' => 'my_custom_template_raw', 225 300 'source' => 'custom', 301 'origin' => null, 226 302 'type' => 'wp_template', 227 303 'description' => 'Just a description', … … 232 308 'status' => 'publish', 233 309 'has_theme_file' => false, 310 'is_custom' => true, 311 'author' => self::$admin_id, 234 312 ), 235 313 $data 236 314 ); 315 } 316 317 public function test_create_item_invalid_author() { 318 wp_set_current_user( self::$admin_id ); 319 $request = new WP_REST_Request( 'POST', '/wp/v2/templates' ); 320 $request->set_body_params( 321 array( 322 'slug' => 'my_custom_template_invalid_author', 323 'description' => 'Just a description', 324 'title' => 'My Template', 325 'content' => 'Content', 326 'author' => -1, 327 ) 328 ); 329 $response = rest_get_server()->dispatch( $request ); 330 $this->assertErrorResponse( 'rest_invalid_author', $response, 400 ); 237 331 } 238 332 … … 371 465 $data = $response->get_data(); 372 466 $properties = $data['schema']['properties']; 373 $this->assertCount( 1 1, $properties );467 $this->assertCount( 14, $properties ); 374 468 $this->assertArrayHasKey( 'id', $properties ); 375 469 $this->assertArrayHasKey( 'description', $properties ); … … 378 472 $this->assertArrayHasKey( 'type', $properties ); 379 473 $this->assertArrayHasKey( 'source', $properties ); 474 $this->assertArrayHasKey( 'origin', $properties ); 380 475 $this->assertArrayHasKey( 'content', $properties ); 381 476 $this->assertArrayHasKey( 'title', $properties ); … … 384 479 $this->assertArrayHasKey( 'wp_id', $properties ); 385 480 $this->assertArrayHasKey( 'has_theme_file', $properties ); 481 $this->assertArrayHasKey( 'is_custom', $properties ); 482 $this->assertArrayHasKey( 'author', $properties ); 386 483 } 387 484
Note: See TracChangeset
for help on using the changeset viewer.