@@ 71-80 (lines=10) @@ | ||
68 | $this->check_get_revision_response( $data[1], $this->revision_1 ); |
|
69 | } |
|
70 | ||
71 | public function test_get_items_no_permission() { |
|
72 | wp_set_current_user( 0 ); |
|
73 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions' ); |
|
74 | $response = $this->server->dispatch( $request ); |
|
75 | ||
76 | $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); |
|
77 | wp_set_current_user( $this->contributor_id ); |
|
78 | $response = $this->server->dispatch( $request ); |
|
79 | $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); |
|
80 | } |
|
81 | ||
82 | public function test_get_items_missing_parent() { |
|
83 | wp_set_current_user( $this->editor_id ); |
|
@@ 138-147 (lines=10) @@ | ||
135 | $this->assertEqualSets( $fields, array_keys( $data ) ); |
|
136 | } |
|
137 | ||
138 | public function test_get_item_no_permission() { |
|
139 | wp_set_current_user( 0 ); |
|
140 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $this->post_id . '/revisions/' . $this->revision_id1 ); |
|
141 | ||
142 | $response = $this->server->dispatch( $request ); |
|
143 | $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); |
|
144 | wp_set_current_user( $this->contributor_id ); |
|
145 | $response = $this->server->dispatch( $request ); |
|
146 | $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); |
|
147 | } |
|
148 | ||
149 | public function test_get_item_missing_parent() { |
|
150 | wp_set_current_user( $this->editor_id ); |
@@ 615-624 (lines=10) @@ | ||
612 | $this->assertEquals( $parent['term_id'], $data['parent'] ); |
|
613 | } |
|
614 | ||
615 | public function test_create_item_invalid_parent() { |
|
616 | wp_set_current_user( $this->administrator ); |
|
617 | $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); |
|
618 | ||
619 | $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); |
|
620 | $request->set_param( 'name', 'My Awesome Term' ); |
|
621 | $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
|
622 | $response = $this->server->dispatch( $request ); |
|
623 | $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); |
|
624 | } |
|
625 | ||
626 | public function test_update_item() { |
|
627 | wp_set_current_user( $this->administrator ); |
|
@@ 662-669 (lines=8) @@ | ||
659 | $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); |
|
660 | } |
|
661 | ||
662 | public function test_update_item_incorrect_permissions() { |
|
663 | wp_set_current_user( $this->subscriber ); |
|
664 | $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); |
|
665 | $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); |
|
666 | $request->set_param( 'name', 'Incorrect permissions' ); |
|
667 | $response = $this->server->dispatch( $request ); |
|
668 | $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); |
|
669 | } |
|
670 | ||
671 | public function test_update_item_parent() { |
|
672 | wp_set_current_user( $this->administrator ); |
|
@@ 685-693 (lines=9) @@ | ||
682 | $this->assertEquals( $parent->term_id, $data['parent'] ); |
|
683 | } |
|
684 | ||
685 | public function test_update_item_invalid_parent() { |
|
686 | wp_set_current_user( $this->administrator ); |
|
687 | $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); |
|
688 | ||
689 | $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); |
|
690 | $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
|
691 | $response = $this->server->dispatch( $request ); |
|
692 | $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); |
|
693 | } |
|
694 | ||
695 | public function test_delete_item() { |
|
696 | wp_set_current_user( $this->administrator ); |
|
@@ 706-713 (lines=8) @@ | ||
703 | $this->assertEquals( 'Deleted Category', $data['name'] ); |
|
704 | } |
|
705 | ||
706 | public function test_delete_item_force_false() { |
|
707 | wp_set_current_user( $this->administrator ); |
|
708 | $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); |
|
709 | $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); |
|
710 | // force defaults to false |
|
711 | $response = $this->server->dispatch( $request ); |
|
712 | $this->assertEquals( 501, $response->get_status() ); |
|
713 | } |
|
714 | ||
715 | public function test_delete_item_invalid_taxonomy() { |
|
716 | wp_set_current_user( $this->administrator ); |
|
@@ 729-735 (lines=7) @@ | ||
726 | $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); |
|
727 | } |
|
728 | ||
729 | public function test_delete_item_incorrect_permissions() { |
|
730 | wp_set_current_user( $this->subscriber ); |
|
731 | $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); |
|
732 | $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); |
|
733 | $response = $this->server->dispatch( $request ); |
|
734 | $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); |
|
735 | } |
|
736 | ||
737 | public function test_prepare_item() { |
|
738 | $term = get_term( 1, 'category' ); |
@@ 518-525 (lines=8) @@ | ||
515 | $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); |
|
516 | } |
|
517 | ||
518 | public function test_update_item_incorrect_permissions() { |
|
519 | wp_set_current_user( $this->subscriber ); |
|
520 | $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); |
|
521 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); |
|
522 | $request->set_param( 'name', 'Incorrect permissions' ); |
|
523 | $response = $this->server->dispatch( $request ); |
|
524 | $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); |
|
525 | } |
|
526 | ||
527 | public function test_update_item_parent_non_hierarchical_taxonomy() { |
|
528 | wp_set_current_user( $this->administrator ); |
|
@@ 527-535 (lines=9) @@ | ||
524 | $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); |
|
525 | } |
|
526 | ||
527 | public function test_update_item_parent_non_hierarchical_taxonomy() { |
|
528 | wp_set_current_user( $this->administrator ); |
|
529 | $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); |
|
530 | ||
531 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_taxonomy_id ); |
|
532 | $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
|
533 | $response = $this->server->dispatch( $request ); |
|
534 | $this->assertErrorResponse( 'rest_taxonomy_not_hierarchical', $response, 400 ); |
|
535 | } |
|
536 | ||
537 | public function test_delete_item() { |
|
538 | wp_set_current_user( $this->administrator ); |
|
@@ 548-555 (lines=8) @@ | ||
545 | $this->assertEquals( 'Deleted Tag', $data['name'] ); |
|
546 | } |
|
547 | ||
548 | public function test_delete_item_force_false() { |
|
549 | wp_set_current_user( $this->administrator ); |
|
550 | $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); |
|
551 | $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); |
|
552 | // force defaults to false |
|
553 | $response = $this->server->dispatch( $request ); |
|
554 | $this->assertEquals( 501, $response->get_status() ); |
|
555 | } |
|
556 | ||
557 | public function test_delete_item_invalid_term() { |
|
558 | wp_set_current_user( $this->administrator ); |
@@ 659-669 (lines=11) @@ | ||
656 | $this->assertErrorResponse( 'rest_cannot_read', $response, 401 ); |
|
657 | } |
|
658 | ||
659 | public function test_get_comment_invalid_post_id_as_admin() { |
|
660 | wp_set_current_user( $this->admin_id ); |
|
661 | $comment_id = $this->factory->comment->create( array( |
|
662 | 'comment_approved' => 1, |
|
663 | 'comment_post_ID' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, |
|
664 | )); |
|
665 | $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id ); |
|
666 | ||
667 | $response = $this->server->dispatch( $request ); |
|
668 | $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); |
|
669 | } |
|
670 | ||
671 | public function test_get_comment_not_approved() { |
|
672 | wp_set_current_user( 0 ); |