- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r41760 r42343 17 17 18 18 public static function wpSetUpBeforeClass( $factory ) { 19 self::$superadmin = $factory->user->create( array( 20 'role' => 'administrator', 21 'user_login' => 'superadmin', 22 ) ); 23 self::$administrator = $factory->user->create( array( 24 'role' => 'administrator', 25 ) ); 26 self::$editor = $factory->user->create( array( 27 'role' => 'editor', 28 ) ); 29 self::$subscriber = $factory->user->create( array( 30 'role' => 'subscriber', 31 ) ); 19 self::$superadmin = $factory->user->create( 20 array( 21 'role' => 'administrator', 22 'user_login' => 'superadmin', 23 ) 24 ); 25 self::$administrator = $factory->user->create( 26 array( 27 'role' => 'administrator', 28 ) 29 ); 30 self::$editor = $factory->user->create( 31 array( 32 'role' => 'editor', 33 ) 34 ); 35 self::$subscriber = $factory->user->create( 36 array( 37 'role' => 'subscriber', 38 ) 39 ); 32 40 if ( is_multisite() ) { 33 41 update_site_option( 'site_admins', array( 'superadmin' ) ); … … 50 58 public function test_context_param() { 51 59 // Collection 52 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );53 $response = $this->server->dispatch( $request ); 54 $data = $response->get_data();60 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 61 $response = $this->server->dispatch( $request ); 62 $data = $response->get_data(); 55 63 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 56 64 $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 57 65 // Single 58 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) );59 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 );60 $response = $this->server->dispatch( $request ); 61 $data = $response->get_data();66 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); 67 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags/' . $tag1 ); 68 $response = $this->server->dispatch( $request ); 69 $data = $response->get_data(); 62 70 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 63 71 $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 65 73 66 74 public function test_registered_query_params() { 67 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );68 $response = $this->server->dispatch( $request ); 69 $data = $response->get_data();70 $keys = array_keys( $data['endpoints'][0]['args'] );75 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 76 $response = $this->server->dispatch( $request ); 77 $data = $response->get_data(); 78 $keys = array_keys( $data['endpoints'][0]['args'] ); 71 79 sort( $keys ); 72 $this->assertEquals( array( 73 'context', 74 'exclude', 75 'hide_empty', 76 'include', 77 'offset', 78 'order', 79 'orderby', 80 'page', 81 'per_page', 82 'post', 83 'search', 84 'slug', 85 ), $keys ); 80 $this->assertEquals( 81 array( 82 'context', 83 'exclude', 84 'hide_empty', 85 'include', 86 'offset', 87 'order', 88 'orderby', 89 'page', 90 'per_page', 91 'post', 92 'search', 93 'slug', 94 ), $keys 95 ); 86 96 } 87 97 88 98 public function test_get_items() { 89 99 $this->factory->tag->create(); 90 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );100 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 91 101 $response = $this->server->dispatch( $request ); 92 102 $this->check_get_taxonomy_terms_response( $response ); … … 103 113 public function test_get_items_hide_empty_arg() { 104 114 $post_id = $this->factory->post->create(); 105 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) );106 $tag2 = $this->factory->tag->create( array( 'name' => 'The Be Sharps' ) );115 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); 116 $tag2 = $this->factory->tag->create( array( 'name' => 'The Be Sharps' ) ); 107 117 wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); 108 118 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 109 119 $request->set_param( 'hide_empty', true ); 110 120 $response = $this->server->dispatch( $request ); 111 $data = $response->get_data();121 $data = $response->get_data(); 112 122 $this->assertEquals( 2, count( $data ) ); 113 123 $this->assertEquals( 'Season 5', $data[0]['name'] ); … … 120 130 121 131 public function test_get_items_include_query() { 122 $id1 = $this->factory->tag->create();123 $id2 = $this->factory->tag->create();124 $id3 = $this->factory->tag->create();132 $id1 = $this->factory->tag->create(); 133 $id2 = $this->factory->tag->create(); 134 $id3 = $this->factory->tag->create(); 125 135 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 126 136 // Orderby=>asc 127 137 $request->set_param( 'include', array( $id3, $id1 ) ); 128 138 $response = $this->server->dispatch( $request ); 129 $data = $response->get_data();139 $data = $response->get_data(); 130 140 $this->assertEquals( 2, count( $data ) ); 131 141 $this->assertEquals( $id1, $data[0]['id'] ); … … 133 143 $request->set_param( 'orderby', 'include' ); 134 144 $response = $this->server->dispatch( $request ); 135 $data = $response->get_data();145 $data = $response->get_data(); 136 146 $this->assertEquals( 2, count( $data ) ); 137 147 $this->assertEquals( $id3, $data[0]['id'] ); … … 143 153 144 154 public function test_get_items_exclude_query() { 145 $id1 = $this->factory->tag->create();146 $id2 = $this->factory->tag->create();147 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );148 $response = $this->server->dispatch( $request ); 149 $data = $response->get_data();155 $id1 = $this->factory->tag->create(); 156 $id2 = $this->factory->tag->create(); 157 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 158 $response = $this->server->dispatch( $request ); 159 $data = $response->get_data(); 150 160 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 151 161 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 152 162 $request->set_param( 'exclude', array( $id2 ) ); 153 163 $response = $this->server->dispatch( $request ); 154 $data = $response->get_data();164 $data = $response->get_data(); 155 165 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 156 166 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); … … 162 172 163 173 public function test_get_items_offset_query() { 164 $id1 = $this->factory->tag->create();165 $id2 = $this->factory->tag->create();166 $id3 = $this->factory->tag->create();167 $id4 = $this->factory->tag->create();174 $id1 = $this->factory->tag->create(); 175 $id2 = $this->factory->tag->create(); 176 $id3 = $this->factory->tag->create(); 177 $id4 = $this->factory->tag->create(); 168 178 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 169 179 $request->set_param( 'offset', 1 ); … … 223 233 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 224 234 // defaults to orderby=name, order=asc 225 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );235 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 226 236 $response = $this->server->dispatch( $request ); 227 237 $this->assertEquals( 200, $response->get_status() ); … … 244 254 $request->set_param( 'order', 'desc' ); 245 255 $response = $this->server->dispatch( $request ); 246 $data = $response->get_data();256 $data = $response->get_data(); 247 257 $this->assertEquals( 200, $response->get_status() ); 248 258 $this->assertEquals( 'Banana', $data[0]['name'] ); … … 260 270 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 261 271 $response = $this->server->dispatch( $request ); 262 $data = $response->get_data();272 $data = $response->get_data(); 263 273 $this->assertEquals( 200, $response->get_status() ); 264 274 $this->assertEquals( 'taco', $data[0]['slug'] ); … … 269 279 public function test_get_items_post_args() { 270 280 $post_id = $this->factory->post->create(); 271 $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) );272 $tag2 = $this->factory->tag->create( array( 'name' => 'Marvel' ) );281 $tag1 = $this->factory->tag->create( array( 'name' => 'DC' ) ); 282 $tag2 = $this->factory->tag->create( array( 'name' => 'Marvel' ) ); 273 283 $this->factory->tag->create( array( 'name' => 'Dark Horse' ) ); 274 284 wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); … … 295 305 296 306 for ( $i = 0; $i < 30; $i++ ) { 297 $tag_ids[] = $this->factory->tag->create( array( 298 'name' => "Tag {$i}", 299 ) ); 307 $tag_ids[] = $this->factory->tag->create( 308 array( 309 'name' => "Tag {$i}", 310 ) 311 ); 300 312 } 301 313 wp_set_object_terms( $post_id, $tag_ids, 'post_tag' ); … … 307 319 $request->set_param( 'orderby', 'id' ); 308 320 $response = $this->server->dispatch( $request ); 309 $tags = $response->get_data();321 $tags = $response->get_data(); 310 322 311 323 $i = 0; … … 321 333 $request->set_param( 'orderby', 'id' ); 322 334 $response = $this->server->dispatch( $request ); 323 $tags = $response->get_data();335 $tags = $response->get_data(); 324 336 325 337 foreach ( $tags as $tag ) { … … 345 357 $controller = new WP_REST_Terms_Controller( 'batman' ); 346 358 $controller->register_routes(); 347 $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'batman' ) ); 348 $term2 = $this->factory->term->create( array( 'name' => 'Mask', 'taxonomy' => 'batman' ) ); 349 $this->factory->term->create( array( 'name' => 'Car', 'taxonomy' => 'batman' ) ); 359 $term1 = $this->factory->term->create( 360 array( 361 'name' => 'Cape', 362 'taxonomy' => 'batman', 363 ) 364 ); 365 $term2 = $this->factory->term->create( 366 array( 367 'name' => 'Mask', 368 'taxonomy' => 'batman', 369 ) 370 ); 371 $this->factory->term->create( 372 array( 373 'name' => 'Car', 374 'taxonomy' => 'batman', 375 ) 376 ); 350 377 $post_id = $this->factory->post->create(); 351 378 wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' ); … … 384 411 385 412 public function test_get_items_slug_arg() { 386 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) );387 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) );413 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 414 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 388 415 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 389 416 $request->set_param( 'slug', 'apple' ); … … 401 428 $this->factory->tag->create( array( 'name' => 'Pizza' ) ); 402 429 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 403 $request->set_param( 'slug', array( 404 'taco', 405 'burrito', 406 'enchilada', 407 ) ); 408 $response = $this->server->dispatch( $request ); 409 $this->assertEquals( 200, $response->get_status() ); 410 $data = $response->get_data(); 430 $request->set_param( 431 'slug', array( 432 'taco', 433 'burrito', 434 'enchilada', 435 ) 436 ); 437 $response = $this->server->dispatch( $request ); 438 $this->assertEquals( 200, $response->get_status() ); 439 $data = $response->get_data(); 411 440 $names = wp_list_pluck( $data, 'name' ); 412 441 sort( $names ); … … 420 449 $this->factory->tag->create( array( 'name' => 'Pizza' ) ); 421 450 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 422 $request->set_param( 'slug', 'taco,burrito, enchilada' );423 $response = $this->server->dispatch( $request ); 424 $this->assertEquals( 200, $response->get_status() ); 425 $data = $response->get_data();451 $request->set_param( 'slug', 'taco,burrito, enchilada' ); 452 $response = $this->server->dispatch( $request ); 453 $this->assertEquals( 200, $response->get_status() ); 454 $data = $response->get_data(); 426 455 $names = wp_list_pluck( $data, 'name' ); 427 456 sort( $names ); … … 431 460 public function test_get_terms_private_taxonomy() { 432 461 register_taxonomy( 'robin', 'post', array( 'public' => false ) ); 433 $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) ); 434 $term2 = $this->factory->term->create( array( 'name' => 'Mask', 'taxonomy' => 'robin' ) ); 435 436 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' ); 462 $term1 = $this->factory->term->create( 463 array( 464 'name' => 'Cape', 465 'taxonomy' => 'robin', 466 ) 467 ); 468 $term2 = $this->factory->term->create( 469 array( 470 'name' => 'Mask', 471 'taxonomy' => 'robin', 472 ) 473 ); 474 475 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' ); 437 476 $response = $this->server->dispatch( $request ); 438 477 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); … … 442 481 // Start of the index 443 482 for ( $i = 0; $i < 50; $i++ ) { 444 $this->factory->tag->create( array( 445 'name' => "Tag {$i}", 446 ) ); 447 } 448 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 449 $response = $this->server->dispatch( $request ); 450 $headers = $response->get_headers(); 483 $this->factory->tag->create( 484 array( 485 'name' => "Tag {$i}", 486 ) 487 ); 488 } 489 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 490 $response = $this->server->dispatch( $request ); 491 $headers = $response->get_headers(); 451 492 $this->assertEquals( 50, $headers['X-WP-Total'] ); 452 493 $this->assertEquals( 5, $headers['X-WP-TotalPages'] ); 453 $next_link = add_query_arg( array( 454 'page' => 2, 455 ), rest_url( 'wp/v2/tags' ) ); 494 $next_link = add_query_arg( 495 array( 496 'page' => 2, 497 ), rest_url( 'wp/v2/tags' ) 498 ); 456 499 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 457 500 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 458 501 // 3rd page 459 $this->factory->tag->create( array( 460 'name' => 'Tag 51', 461 ) ); 502 $this->factory->tag->create( 503 array( 504 'name' => 'Tag 51', 505 ) 506 ); 462 507 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 463 508 $request->set_param( 'page', 3 ); 464 509 $response = $this->server->dispatch( $request ); 465 $headers = $response->get_headers();510 $headers = $response->get_headers(); 466 511 $this->assertEquals( 51, $headers['X-WP-Total'] ); 467 512 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 468 $prev_link = add_query_arg( array( 469 'page' => 2, 470 ), rest_url( 'wp/v2/tags' ) ); 513 $prev_link = add_query_arg( 514 array( 515 'page' => 2, 516 ), rest_url( 'wp/v2/tags' ) 517 ); 471 518 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 472 $next_link = add_query_arg( array( 473 'page' => 4, 474 ), rest_url( 'wp/v2/tags' ) ); 519 $next_link = add_query_arg( 520 array( 521 'page' => 4, 522 ), rest_url( 'wp/v2/tags' ) 523 ); 475 524 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 476 525 // Last page … … 478 527 $request->set_param( 'page', 6 ); 479 528 $response = $this->server->dispatch( $request ); 480 $headers = $response->get_headers();529 $headers = $response->get_headers(); 481 530 $this->assertEquals( 51, $headers['X-WP-Total'] ); 482 531 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 483 $prev_link = add_query_arg( array( 484 'page' => 5, 485 ), rest_url( 'wp/v2/tags' ) ); 532 $prev_link = add_query_arg( 533 array( 534 'page' => 5, 535 ), rest_url( 'wp/v2/tags' ) 536 ); 486 537 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 487 538 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); … … 490 541 $request->set_param( 'page', 8 ); 491 542 $response = $this->server->dispatch( $request ); 492 $headers = $response->get_headers();543 $headers = $response->get_headers(); 493 544 $this->assertEquals( 51, $headers['X-WP-Total'] ); 494 545 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 495 $prev_link = add_query_arg( array( 496 'page' => 6, 497 ), rest_url( 'wp/v2/tags' ) ); 546 $prev_link = add_query_arg( 547 array( 548 'page' => 6, 549 ), rest_url( 'wp/v2/tags' ) 550 ); 498 551 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 499 552 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); … … 508 561 509 562 public function test_get_item() { 510 $id = $this->factory->tag->create();511 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id );563 $id = $this->factory->tag->create(); 564 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 512 565 $response = $this->server->dispatch( $request ); 513 566 $this->check_get_taxonomy_term_response( $response, $id ); … … 515 568 516 569 public function test_get_term_invalid_term() { 517 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );570 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 518 571 $response = $this->server->dispatch( $request ); 519 572 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); … … 531 584 public function test_get_term_private_taxonomy() { 532 585 register_taxonomy( 'robin', 'post', array( 'public' => false ) ); 533 $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) ); 534 535 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 ); 586 $term1 = $this->factory->term->create( 587 array( 588 'name' => 'Cape', 589 'taxonomy' => 'robin', 590 ) 591 ); 592 593 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 ); 536 594 $response = $this->server->dispatch( $request ); 537 595 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); … … 540 598 public function test_get_item_incorrect_taxonomy() { 541 599 register_taxonomy( 'robin', 'post' ); 542 $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) ); 543 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term1 ); 600 $term1 = $this->factory->term->create( 601 array( 602 'name' => 'Cape', 603 'taxonomy' => 'robin', 604 ) 605 ); 606 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term1 ); 544 607 $response = $this->server->dispatch( $request ); 545 608 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); … … 555 618 $this->assertEquals( 201, $response->get_status() ); 556 619 $headers = $response->get_headers(); 557 $data = $response->get_data();620 $data = $response->get_data(); 558 621 $this->assertContains( '/wp/v2/tags/' . $data['id'], $headers['Location'] ); 559 622 $this->assertEquals( 'My Awesome Term', $data['name'] ); … … 572 635 public function test_create_item_missing_arguments() { 573 636 wp_set_current_user( self::$administrator ); 574 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' );637 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 575 638 $response = $this->server->dispatch( $request ); 576 639 $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 ); … … 593 656 'description' => 'Original Description', 594 657 'slug' => 'original-slug', 595 596 $term = get_term_by( 'id', $this->factory->tag->create( $orig_args ), 'post_tag' );597 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id );658 ); 659 $term = get_term_by( 'id', $this->factory->tag->create( $orig_args ), 'post_tag' ); 660 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 598 661 $request->set_param( 'name', 'New Name' ); 599 662 $request->set_param( 'description', 'New Description' ); … … 636 699 public function test_update_item_incorrect_permissions() { 637 700 wp_set_current_user( self::$subscriber ); 638 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );701 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 639 702 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 640 703 $request->set_param( 'name', 'Incorrect permissions' ); … … 648 711 public function test_update_item_with_edit_term_cap_granted() { 649 712 wp_set_current_user( self::$subscriber ); 650 $term = $this->factory->tag->create_and_get();713 $term = $this->factory->tag->create_and_get(); 651 714 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 652 715 $request->set_param( 'name', 'New Name' ); … … 673 736 public function test_update_item_with_edit_term_cap_revoked() { 674 737 wp_set_current_user( self::$administrator ); 675 $term = $this->factory->tag->create_and_get();738 $term = $this->factory->tag->create_and_get(); 676 739 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 677 740 $request->set_param( 'name', 'New Name' ); … … 742 805 wp_set_current_user( self::$editor ); 743 806 $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) ); 744 $this->verify_tag_roundtrip( array( 745 'name' => '\o/ ¯\_(ツ)_/¯', 746 'description' => '\o/ ¯\_(ツ)_/¯', 747 ), array( 748 'name' => '\o/ ¯\_(ツ)_/¯', 749 'description' => '\o/ ¯\_(ツ)_/¯', 750 ) ); 807 $this->verify_tag_roundtrip( 808 array( 809 'name' => '\o/ ¯\_(ツ)_/¯', 810 'description' => '\o/ ¯\_(ツ)_/¯', 811 ), array( 812 'name' => '\o/ ¯\_(ツ)_/¯', 813 'description' => '\o/ ¯\_(ツ)_/¯', 814 ) 815 ); 751 816 } 752 817 … … 755 820 if ( is_multisite() ) { 756 821 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 757 $this->verify_tag_roundtrip( array( 822 $this->verify_tag_roundtrip( 823 array( 824 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 825 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 826 ), array( 827 'name' => 'div strong', 828 'description' => 'div <strong>strong</strong> oh noes', 829 ) 830 ); 831 } else { 832 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 833 $this->verify_tag_roundtrip( 834 array( 835 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 836 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 837 ), array( 838 'name' => 'div strong', 839 'description' => 'div <strong>strong</strong> oh noes', 840 ) 841 ); 842 } 843 } 844 845 public function test_tag_roundtrip_as_superadmin() { 846 wp_set_current_user( self::$superadmin ); 847 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 848 $this->verify_tag_roundtrip( 849 array( 850 'name' => '\\\&\\\ & &invalid; < < &lt;', 851 'description' => '\\\&\\\ & &invalid; < < &lt;', 852 ), array( 853 'name' => '\\\&\\\ & &invalid; < < &lt;', 854 'description' => '\\\&\\\ & &invalid; < < &lt;', 855 ) 856 ); 857 } 858 859 public function test_tag_roundtrip_as_superadmin_html() { 860 wp_set_current_user( self::$superadmin ); 861 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 862 $this->verify_tag_roundtrip( 863 array( 758 864 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 759 865 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', … … 761 867 'name' => 'div strong', 762 868 'description' => 'div <strong>strong</strong> oh noes', 763 ) ); 764 } else { 765 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 766 $this->verify_tag_roundtrip( array( 767 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 768 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 769 ), array( 770 'name' => 'div strong', 771 'description' => 'div <strong>strong</strong> oh noes', 772 ) ); 773 } 774 } 775 776 public function test_tag_roundtrip_as_superadmin() { 777 wp_set_current_user( self::$superadmin ); 778 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 779 $this->verify_tag_roundtrip( array( 780 'name' => '\\\&\\\ & &invalid; < < &lt;', 781 'description' => '\\\&\\\ & &invalid; < < &lt;', 782 ), array( 783 'name' => '\\\&\\\ & &invalid; < < &lt;', 784 'description' => '\\\&\\\ & &invalid; < < &lt;', 785 ) ); 786 } 787 788 public function test_tag_roundtrip_as_superadmin_html() { 789 wp_set_current_user( self::$superadmin ); 790 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 791 $this->verify_tag_roundtrip( array( 792 'name' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 793 'description' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 794 ), array( 795 'name' => 'div strong', 796 'description' => 'div <strong>strong</strong> oh noes', 797 ) ); 869 ) 870 ); 798 871 } 799 872 800 873 public function test_delete_item() { 801 874 wp_set_current_user( self::$administrator ); 802 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );875 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 803 876 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 804 877 $request->set_param( 'force', true ); … … 814 887 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 815 888 816 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );889 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 817 890 $response = $this->server->dispatch( $request ); 818 891 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); … … 825 898 public function test_delete_item_invalid_term() { 826 899 wp_set_current_user( self::$administrator ); 827 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );900 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 828 901 $response = $this->server->dispatch( $request ); 829 902 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); … … 832 905 public function test_delete_item_incorrect_permissions() { 833 906 wp_set_current_user( self::$subscriber ); 834 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );835 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );907 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 908 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 836 909 $response = $this->server->dispatch( $request ); 837 910 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); … … 843 916 public function test_delete_item_with_delete_term_cap_granted() { 844 917 wp_set_current_user( self::$subscriber ); 845 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );918 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 846 919 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 847 920 $request->set_param( 'force', true ); … … 869 942 public function test_delete_item_with_delete_term_cap_revoked() { 870 943 wp_set_current_user( self::$administrator ); 871 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );944 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 872 945 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 873 946 $request->set_param( 'force', true ); … … 888 961 889 962 public function test_prepare_item() { 890 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );891 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id );892 $response = $this->server->dispatch( $request ); 893 $data = $response->get_data();963 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 964 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id ); 965 $response = $this->server->dispatch( $request ); 966 $data = $response->get_data(); 894 967 895 968 $this->check_taxonomy_term( $term, $data, $response->get_links() ); … … 897 970 898 971 public function test_get_item_schema() { 899 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );900 $response = $this->server->dispatch( $request );901 $data = $response->get_data();972 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 973 $response = $this->server->dispatch( $request ); 974 $data = $response->get_data(); 902 975 $properties = $data['schema']['properties']; 903 976 $this->assertEquals( 8, count( $properties ) ); … … 914 987 915 988 public function test_get_item_schema_non_hierarchical() { 916 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' );917 $response = $this->server->dispatch( $request );918 $data = $response->get_data();989 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 990 $response = $this->server->dispatch( $request ); 991 $data = $response->get_data(); 919 992 $properties = $data['schema']['properties']; 920 993 $this->assertArrayHasKey( 'id', $properties ); … … 931 1004 ); 932 1005 933 register_rest_field( 'tag', 'my_custom_int', array( 934 'schema' => $schema, 935 'get_callback' => array( $this, 'additional_field_get_callback' ), 936 ) ); 1006 register_rest_field( 1007 'tag', 'my_custom_int', array( 1008 'schema' => $schema, 1009 'get_callback' => array( $this, 'additional_field_get_callback' ), 1010 ) 1011 ); 937 1012 938 1013 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/tags' ); 939 1014 940 1015 $response = $this->server->dispatch( $request ); 941 $data = $response->get_data();1016 $data = $response->get_data(); 942 1017 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); 943 1018 $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); 944 1019 945 $tag_id = $this->factory->tag->create();1020 $tag_id = $this->factory->tag->create(); 946 1021 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); 947 1022 … … 961 1036 ); 962 1037 963 register_rest_field( 'tag', 'my_custom_int', array( 964 'schema' => $schema, 965 'get_callback' => array( $this, 'additional_field_get_callback' ), 966 'update_callback' => array( $this, 'additional_field_update_callback' ), 967 ) ); 1038 register_rest_field( 1039 'tag', 'my_custom_int', array( 1040 'schema' => $schema, 1041 'get_callback' => array( $this, 'additional_field_get_callback' ), 1042 'update_callback' => array( $this, 'additional_field_update_callback' ), 1043 ) 1044 ); 968 1045 969 1046 wp_set_current_user( self::$administrator ); … … 971 1048 // Check for error on update. 972 1049 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/tags/%d', $tag_id ) ); 973 $request->set_body_params( array( 974 'my_custom_int' => 'returnError', 975 ) ); 1050 $request->set_body_params( 1051 array( 1052 'my_custom_int' => 'returnError', 1053 ) 1054 ); 976 1055 977 1056 $response = $this->server->dispatch( $request ); … … 990 1069 991 1070 $tags = $this->factory->tag->create_many( 2 ); 992 $p = $this->factory->post->create();1071 $p = $this->factory->post->create(); 993 1072 wp_set_object_terms( $p, $tags[0], 'post_tag' ); 994 1073 … … 996 1075 $request->set_param( 'post', $p ); 997 1076 $response = $this->server->dispatch( $request ); 998 $found_1 = wp_list_pluck( $response->data, 'id' );1077 $found_1 = wp_list_pluck( $response->data, 'id' ); 999 1078 1000 1079 unset( $request, $response ); … … 1005 1084 $request->set_param( 'post', $p ); 1006 1085 $response = $this->server->dispatch( $request ); 1007 $found_2 = wp_list_pluck( $response->data, 'id' );1086 $found_2 = wp_list_pluck( $response->data, 'id' ); 1008 1087 1009 1088 $this->assertEqualSets( $found_1, $found_2 ); … … 1048 1127 $this->assertEquals( $term->slug, $data['slug'] ); 1049 1128 $this->assertEquals( $term->description, $data['description'] ); 1050 $this->assertEquals( get_term_link( $term ), 1129 $this->assertEquals( get_term_link( $term ), $data['link'] ); 1051 1130 $this->assertEquals( $term->count, $data['count'] ); 1052 1131 $taxonomy = get_taxonomy( $term->taxonomy ); … … 1075 1154 1076 1155 $data = $response->get_data(); 1077 $tag = get_term( $id, 'post_tag' );1156 $tag = get_term( $id, 'post_tag' ); 1078 1157 $this->check_taxonomy_term( $tag, $data, $response->get_links() ); 1079 1158 }
Note: See TracChangeset
for help on using the changeset viewer.