- Timestamp:
- 11/05/2019 08:41:12 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r46586 r46657 17 17 protected static $subscriber; 18 18 19 protected static $tag_ids = array(); 20 protected static $total_tags = 30; 21 protected static $per_page = 50; 22 19 23 public static function wpSetUpBeforeClass( $factory ) { 20 24 self::$superadmin = $factory->user->create( … … 44 48 ) 45 49 ); 50 46 51 if ( is_multisite() ) { 47 52 update_site_option( 'site_admins', array( 'superadmin' ) ); 53 } 54 55 // Set up tags for pagination tests. 56 for ( $i = 0; $i < self::$total_tags; $i++ ) { 57 $tag_ids[] = $factory->tag->create( 58 array( 59 'name' => "Tag {$i}", 60 ) 61 ); 48 62 } 49 63 } … … 54 68 self::delete_user( self::$editor ); 55 69 self::delete_user( self::$subscriber ); 70 71 // Remove tags for pagination tests. 72 foreach ( self::$tag_ids as $tag_id ) { 73 wp_delete_term( $tag_id, 'post_tag' ); 74 } 56 75 } 57 76 … … 155 174 public function test_get_items() { 156 175 $this->factory->tag->create(); 157 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 176 177 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 178 $request->set_param( 'per_page', self::$per_page ); 158 179 $response = rest_get_server()->dispatch( $request ); 159 180 $this->check_get_taxonomy_terms_response( $response ); … … 162 183 public function test_get_items_invalid_permission_for_context() { 163 184 wp_set_current_user( 0 ); 185 164 186 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 165 187 $request->set_param( 'context', 'edit' ); … … 172 194 $tag1 = $this->factory->tag->create( array( 'name' => 'Season 5' ) ); 173 195 $tag2 = $this->factory->tag->create( array( 'name' => 'The Be Sharps' ) ); 196 174 197 wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); 198 175 199 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 176 200 $request->set_param( 'hide_empty', true ); … … 180 204 $this->assertEquals( 'Season 5', $data[0]['name'] ); 181 205 $this->assertEquals( 'The Be Sharps', $data[1]['name'] ); 182 // invalid value should fail 206 207 // Invalid 'hide_empty' should error. 183 208 $request->set_param( 'hide_empty', 'nothanks' ); 184 209 $response = rest_get_server()->dispatch( $request ); … … 187 212 188 213 public function test_get_items_include_query() { 189 $id1 = $this->factory->tag->create(); 190 $id2 = $this->factory->tag->create(); 191 $id3 = $this->factory->tag->create(); 192 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 193 // Orderby=>asc 194 $request->set_param( 'include', array( $id3, $id1 ) ); 214 $id1 = $this->factory->tag->create(); 215 $id2 = $this->factory->tag->create(); 216 217 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 218 219 // 'orderby' => 'asc'. 220 $request->set_param( 'include', array( $id2, $id1 ) ); 195 221 $response = rest_get_server()->dispatch( $request ); 196 222 $data = $response->get_data(); 197 223 $this->assertEquals( 2, count( $data ) ); 198 224 $this->assertEquals( $id1, $data[0]['id'] ); 199 // Orderby=>include 225 226 // 'orderby' => 'include'. 200 227 $request->set_param( 'orderby', 'include' ); 201 228 $response = rest_get_server()->dispatch( $request ); 202 229 $data = $response->get_data(); 203 230 $this->assertEquals( 2, count( $data ) ); 204 $this->assertEquals( $id3, $data[0]['id'] ); 205 // Include invalid value shoud fail 231 $this->assertEquals( $id2, $data[0]['id'] ); 232 233 // Invalid 'include' should error. 206 234 $request->set_param( 'include', array( 'myterm' ) ); 207 235 $response = rest_get_server()->dispatch( $request ); … … 210 238 211 239 public function test_get_items_exclude_query() { 212 $id1 = $this->factory->tag->create(); 213 $id2 = $this->factory->tag->create(); 214 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 240 $id1 = $this->factory->tag->create(); 241 $id2 = $this->factory->tag->create(); 242 243 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 244 $request->set_param( 'per_page', self::$per_page ); 215 245 $response = rest_get_server()->dispatch( $request ); 216 246 $data = $response->get_data(); 217 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 218 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 247 $ids = wp_list_pluck( $data, 'id' ); 248 $this->assertTrue( in_array( $id1, $ids, true ) ); 249 $this->assertTrue( in_array( $id2, $ids, true ) ); 250 219 251 $request->set_param( 'exclude', array( $id2 ) ); 220 252 $response = rest_get_server()->dispatch( $request ); 221 253 $data = $response->get_data(); 222 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 223 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 224 // Invalid exclude value should fail 254 $ids = wp_list_pluck( $data, 'id' ); 255 $this->assertTrue( in_array( $id1, $ids, true ) ); 256 $this->assertFalse( in_array( $id2, $ids, true ) ); 257 258 // Invalid 'exclude' should error. 225 259 $request->set_param( 'exclude', array( 'invalid' ) ); 226 260 $response = rest_get_server()->dispatch( $request ); … … 229 263 230 264 public function test_get_items_offset_query() { 231 $id1 = $this->factory->tag->create(); 232 $id2 = $this->factory->tag->create(); 233 $id3 = $this->factory->tag->create(); 234 $id4 = $this->factory->tag->create(); 235 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 265 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 266 $request->set_param( 'per_page', self::$per_page ); 236 267 $request->set_param( 'offset', 1 ); 237 268 $response = rest_get_server()->dispatch( $request ); 238 $this->assertCount( 3, $response->get_data() ); 239 // 'offset' works with 'per_page' 269 $this->assertCount( self::$total_tags - 1, $response->get_data() ); 270 271 // 'offset' works with 'per_page'. 240 272 $request->set_param( 'per_page', 2 ); 241 273 $response = rest_get_server()->dispatch( $request ); 242 274 $this->assertCount( 2, $response->get_data() ); 243 // 'offset' takes priority over 'page' 275 276 // 'offset' takes priority over 'page'. 244 277 $request->set_param( 'page', 3 ); 245 278 $response = rest_get_server()->dispatch( $request ); 246 279 $this->assertCount( 2, $response->get_data() ); 247 // 'offset' invalid value shoudl fail 280 281 // Invalid 'offset' should error. 248 282 $request->set_param( 'offset', 'moreplease' ); 249 283 $response = rest_get_server()->dispatch( $request ); … … 254 288 public function test_get_items_orderby_args() { 255 289 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 256 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 290 $tag2 = $this->factory->tag->create( array( 'name' => 'Zucchini' ) ); 291 257 292 /* 258 293 * Tests: … … 269 304 $data = $response->get_data(); 270 305 $this->assertEquals( 1, count( $data ) ); 271 $this->assertEquals( 'Banana', $data[0]['name'] ); 306 $this->assertEquals( 'Zucchini', $data[0]['name'] ); 307 272 308 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 273 309 $request->set_param( 'orderby', 'name' ); … … 279 315 $this->assertEquals( 2, count( $data ) ); 280 316 $this->assertEquals( 'Apple', $data[0]['name'] ); 281 // Invalid orderby should fail. 317 318 // Invalid 'orderby' should error. 282 319 $request->set_param( 'orderby', 'invalid' ); 283 320 $response = rest_get_server()->dispatch( $request ); … … 289 326 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 290 327 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 291 // defaults to orderby=name, order=asc 328 329 // Defaults to 'orderby' => 'name', 'order' => 'asc'. 292 330 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 293 331 $response = rest_get_server()->dispatch( $request ); … … 297 335 $this->assertEquals( 'Banana', $data[1]['name'] ); 298 336 $this->assertEquals( 'Cantaloupe', $data[2]['name'] ); 299 // orderby=id, with default order=asc 337 338 // 'orderby' => 'id', with default 'order' => 'asc'. 300 339 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 301 340 $request->set_param( 'orderby', 'id' ); … … 303 342 $this->assertEquals( 200, $response->get_status() ); 304 343 $data = $response->get_data(); 305 $this->assertEquals( 'Cantaloupe', $data[0]['name'] ); 306 $this->assertEquals( 'Apple', $data[1]['name'] ); 307 $this->assertEquals( 'Banana', $data[2]['name'] ); 308 // orderby=id, order=desc 344 $this->assertEquals( 'Tag 0', $data[0]['name'] ); 345 $this->assertEquals( 'Tag 1', $data[1]['name'] ); 346 $this->assertEquals( 'Tag 2', $data[2]['name'] ); 347 348 // 'orderby' => 'id', 'order' => 'desc'. 309 349 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 310 350 $request->set_param( 'orderby', 'id' ); … … 339 379 $tag2 = $this->factory->tag->create( array( 'name' => 'Marvel' ) ); 340 380 $this->factory->tag->create( array( 'name' => 'Dark Horse' ) ); 381 341 382 wp_set_object_terms( $post_id, array( $tag1, $tag2 ), 'post_tag' ); 342 383 … … 350 391 $this->assertEquals( 'DC', $data[0]['name'] ); 351 392 352 // Invalid postshould error.393 // Invalid 'post' should error. 353 394 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 354 395 $request->set_param( 'post', 'invalid-post' ); … … 359 400 public function test_get_terms_post_args_paging() { 360 401 $post_id = $this->factory->post->create(); 361 $tag_ids = array(); 362 363 for ( $i = 0; $i < 30; $i++ ) { 364 $tag_ids[] = $this->factory->tag->create( 365 array( 366 'name' => "Tag {$i}", 367 ) 368 ); 369 } 370 wp_set_object_terms( $post_id, $tag_ids, 'post_tag' ); 402 403 wp_set_object_terms( $post_id, self::$tag_ids, 'post_tag' ); 371 404 372 405 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); … … 433 466 ); 434 467 $post_id = $this->factory->post->create(); 468 435 469 wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' ); 436 470 … … 448 482 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 449 483 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 484 450 485 /* 451 486 * Tests: … … 459 494 $this->assertEquals( 1, count( $data ) ); 460 495 $this->assertEquals( 'Apple', $data[0]['name'] ); 496 461 497 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 462 498 $request->set_param( 'search', 'Garbage' ); … … 468 504 469 505 public function test_get_items_slug_arg() { 470 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 471 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 506 $tag1 = $this->factory->tag->create( array( 'name' => 'Apple' ) ); 507 $tag2 = $this->factory->tag->create( array( 'name' => 'Banana' ) ); 508 472 509 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 473 510 $request->set_param( 'slug', 'apple' ); … … 484 521 $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) ); 485 522 $this->factory->tag->create( array( 'name' => 'Pizza' ) ); 523 486 524 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 487 525 $request->set_param( … … 506 544 $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) ); 507 545 $this->factory->tag->create( array( 'name' => 'Pizza' ) ); 546 508 547 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 509 548 $request->set_param( 'slug', 'taco,burrito, enchilada' ); … … 537 576 538 577 public function test_get_terms_pagination_headers() { 539 // Start of the index 540 for ( $i = 0; $i < 50; $i++ ) { 541 $this->factory->tag->create( 542 array( 543 'name' => "Tag {$i}", 544 ) 545 ); 546 } 578 $total_tags = self::$total_tags; 579 $total_pages = (int) ceil( $total_tags / 10 ); 580 581 // Start of the index. 547 582 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 548 583 $response = rest_get_server()->dispatch( $request ); 549 584 $headers = $response->get_headers(); 550 $this->assertEquals( 50, $headers['X-WP-Total'] );551 $this->assertEquals( 5, $headers['X-WP-TotalPages'] );585 $this->assertEquals( $total_tags, $headers['X-WP-Total'] ); 586 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 552 587 $next_link = add_query_arg( 553 588 array( … … 558 593 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 559 594 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 560 // 3rd page 561 $this->factory->tag->create( 562 array( 563 'name' => 'Tag 51', 564 ) 565 ); 595 596 // 3rd page. 597 $this->factory->tag->create(); 598 $total_tags++; 599 $total_pages++; 566 600 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 567 601 $request->set_param( 'page', 3 ); 568 602 $response = rest_get_server()->dispatch( $request ); 569 603 $headers = $response->get_headers(); 570 $this->assertEquals( 51, $headers['X-WP-Total'] );571 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );604 $this->assertEquals( $total_tags, $headers['X-WP-Total'] ); 605 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 572 606 $prev_link = add_query_arg( 573 607 array( … … 584 618 ); 585 619 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 586 // Last page 587 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 588 $request->set_param( 'page', 6 ); 620 621 // Last page. 622 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 623 $request->set_param( 'page', $total_pages ); 589 624 $response = rest_get_server()->dispatch( $request ); 590 625 $headers = $response->get_headers(); 591 $this->assertEquals( 51, $headers['X-WP-Total'] );592 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );626 $this->assertEquals( $total_tags, $headers['X-WP-Total'] ); 627 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 593 628 $prev_link = add_query_arg( 594 629 array( 595 'page' => 5,630 'page' => $total_pages - 1, 596 631 ), 597 632 rest_url( 'wp/v2/tags' ) … … 599 634 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 600 635 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); 601 // Out of bounds 602 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 603 $request->set_param( 'page', 8 ); 636 637 // Out of bounds. 638 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 639 $request->set_param( 'page', 100 ); 604 640 $response = rest_get_server()->dispatch( $request ); 605 641 $headers = $response->get_headers(); 606 $this->assertEquals( 51, $headers['X-WP-Total'] );607 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );642 $this->assertEquals( $total_tags, $headers['X-WP-Total'] ); 643 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 608 644 $prev_link = add_query_arg( 609 645 array( 610 'page' => 6,646 'page' => $total_pages, 611 647 ), 612 648 rest_url( 'wp/v2/tags' ) … … 624 660 625 661 public function test_get_item() { 626 $id = $this->factory->tag->create(); 662 $id = $this->factory->tag->create(); 663 627 664 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 628 665 $response = rest_get_server()->dispatch( $request ); … … 634 671 */ 635 672 public function test_get_item_meta() { 636 $id = $this->factory->tag->create(); 673 $id = $this->factory->tag->create(); 674 637 675 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 638 676 $response = rest_get_server()->dispatch( $request ); … … 655 693 */ 656 694 public function test_get_item_meta_registered_for_different_taxonomy() { 657 $id = $this->factory->tag->create(); 695 $id = $this->factory->tag->create(); 696 658 697 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 659 698 $response = rest_get_server()->dispatch( $request ); … … 673 712 public function test_get_item_invalid_permission_for_context() { 674 713 $id = $this->factory->tag->create(); 714 675 715 wp_set_current_user( 0 ); 716 676 717 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $id ); 677 718 $request->set_param( 'context', 'edit' ); … … 696 737 public function test_get_item_incorrect_taxonomy() { 697 738 register_taxonomy( 'robin', 'post' ); 698 $term1 = $this->factory->term->create(739 $term1 = $this->factory->term->create( 699 740 array( 700 741 'name' => 'Cape', … … 702 743 ) 703 744 ); 745 704 746 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term1 ); 705 747 $response = rest_get_server()->dispatch( $request ); … … 709 751 public function test_create_item() { 710 752 wp_set_current_user( self::$administrator ); 753 711 754 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 712 755 $request->set_param( 'name', 'My Awesome Term' ); … … 725 768 public function test_create_item_contributor() { 726 769 wp_set_current_user( self::$contributor ); 770 727 771 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 728 772 $request->set_param( 'name', 'My Awesome Term' ); … … 741 785 public function test_create_item_incorrect_permissions() { 742 786 wp_set_current_user( self::$subscriber ); 787 743 788 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 744 789 $request->set_param( 'name', 'Incorrect permissions' ); … … 749 794 public function test_create_item_missing_arguments() { 750 795 wp_set_current_user( self::$administrator ); 796 751 797 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 752 798 $response = rest_get_server()->dispatch( $request ); … … 766 812 public function test_create_item_with_meta() { 767 813 wp_set_current_user( self::$administrator ); 814 768 815 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 769 816 $request->set_param( 'name', 'My Awesome Term' ); … … 780 827 public function test_create_item_with_meta_wrong_id() { 781 828 wp_set_current_user( self::$administrator ); 829 782 830 $existing_tag_id = $this->factory->tag->create( array( 'name' => 'My Not So Awesome Term' ) ); 783 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 831 832 $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 784 833 $request->set_param( 'name', 'My Awesome Term' ); 785 834 $request->set_param( 'meta', array( 'test_tag_single' => 'hello' ) ); … … 797 846 public function test_update_item() { 798 847 wp_set_current_user( self::$administrator ); 848 799 849 $orig_args = array( 800 850 'name' => 'Original Name', … … 802 852 'slug' => 'original-slug', 803 853 ); 804 $term = get_term_by( 'id', $this->factory->tag->create( $orig_args ), 'post_tag' ); 805 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 854 855 $term = get_term_by( 'id', $this->factory->tag->create( $orig_args ), 'post_tag' ); 856 857 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 806 858 $request->set_param( 'name', 'New Name' ); 807 859 $request->set_param( 'description', 'New Description' ); … … 828 880 public function test_update_item_no_change() { 829 881 wp_set_current_user( self::$administrator ); 882 830 883 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 831 884 832 $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); 833 885 $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); 834 886 $response = rest_get_server()->dispatch( $request ); 835 887 $this->assertEquals( 200, $response->get_status() ); … … 847 899 public function test_update_item_invalid_term() { 848 900 wp_set_current_user( self::$administrator ); 901 849 902 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 850 903 $request->set_param( 'name', 'Invalid Term' ); … … 855 908 public function test_update_item_incorrect_permissions() { 856 909 wp_set_current_user( self::$subscriber ); 857 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 910 911 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 912 858 913 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 859 914 $request->set_param( 'name', 'Incorrect permissions' ); … … 867 922 public function test_update_item_with_edit_term_cap_granted() { 868 923 wp_set_current_user( self::$subscriber ); 869 $term = $this->factory->tag->create_and_get(); 924 925 $term = $this->factory->tag->create_and_get(); 926 870 927 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 871 928 $request->set_param( 'name', 'New Name' ); … … 892 949 public function test_update_item_with_edit_term_cap_revoked() { 893 950 wp_set_current_user( self::$administrator ); 894 $term = $this->factory->tag->create_and_get(); 951 952 $term = $this->factory->tag->create_and_get(); 953 895 954 $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 896 955 $request->set_param( 'name', 'New Name' ); … … 912 971 public function test_update_item_parent_non_hierarchical_taxonomy() { 913 972 wp_set_current_user( self::$administrator ); 973 914 974 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 915 975 … … 960 1020 public function test_tag_roundtrip_as_editor() { 961 1021 wp_set_current_user( self::$editor ); 1022 962 1023 $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) ); 963 1024 $this->verify_tag_roundtrip( … … 975 1036 public function test_tag_roundtrip_as_editor_html() { 976 1037 wp_set_current_user( self::$editor ); 1038 977 1039 if ( is_multisite() ) { 978 1040 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); … … 1004 1066 public function test_tag_roundtrip_as_superadmin() { 1005 1067 wp_set_current_user( self::$superadmin ); 1068 1006 1069 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1007 1070 $this->verify_tag_roundtrip( … … 1019 1082 public function test_tag_roundtrip_as_superadmin_html() { 1020 1083 wp_set_current_user( self::$superadmin ); 1084 1021 1085 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 1022 1086 $this->verify_tag_roundtrip( … … 1034 1098 public function test_delete_item() { 1035 1099 wp_set_current_user( self::$administrator ); 1036 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1100 1101 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1102 1037 1103 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 1038 1104 $request->set_param( 'force', true ); … … 1046 1112 public function test_delete_item_no_trash() { 1047 1113 wp_set_current_user( self::$administrator ); 1114 1048 1115 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1049 1116 … … 1059 1126 public function test_delete_item_invalid_term() { 1060 1127 wp_set_current_user( self::$administrator ); 1128 1061 1129 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 1062 1130 $response = rest_get_server()->dispatch( $request ); … … 1066 1134 public function test_delete_item_incorrect_permissions() { 1067 1135 wp_set_current_user( self::$subscriber ); 1068 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 1136 1137 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 1138 1069 1139 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 1070 1140 $response = rest_get_server()->dispatch( $request ); … … 1077 1147 public function test_delete_item_with_delete_term_cap_granted() { 1078 1148 wp_set_current_user( self::$subscriber ); 1079 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1149 1150 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1151 1080 1152 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 1081 1153 $request->set_param( 'force', true ); … … 1103 1175 public function test_delete_item_with_delete_term_cap_revoked() { 1104 1176 wp_set_current_user( self::$administrator ); 1105 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1177 1178 $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 1179 1106 1180 $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 1107 1181 $request->set_param( 'force', true ); … … 1122 1196 1123 1197 public function test_prepare_item() { 1124 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 1198 $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 1199 1125 1200 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $term->term_id ); 1126 1201 $response = rest_get_server()->dispatch( $request ); … … 1196 1271 $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] ); 1197 1272 1198 $tag_id = $this->factory->tag->create();1199 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); 1200 1273 $tag_id = $this->factory->tag->create(); 1274 1275 $request = new WP_REST_Request( 'GET', '/wp/v2/tags/' . $tag_id ); 1201 1276 $response = rest_get_server()->dispatch( $request ); 1202 1277 $this->assertArrayHasKey( 'my_custom_int', $response->data ); … … 1225 1300 1226 1301 wp_set_current_user( self::$administrator ); 1302 1227 1303 $tag_id = $this->factory->tag->create(); 1304 1228 1305 // Check for error on update. 1229 1306 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/tags/%d', $tag_id ) );
Note: See TracChangeset
for help on using the changeset viewer.