@@ 593-608 (lines=16) @@ | ||
590 | $this->check_add_edit_user_response( $response ); |
|
591 | } |
|
592 | ||
593 | public function test_create_user_without_permission() { |
|
594 | wp_set_current_user( $this->editor ); |
|
595 | ||
596 | $params = array( |
|
597 | 'username' => 'homersimpson', |
|
598 | 'password' => 'stupidsexyflanders', |
|
599 | 'email' => '[email protected]', |
|
600 | ); |
|
601 | ||
602 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
|
603 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
604 | $request->set_body_params( $params ); |
|
605 | $response = $this->server->dispatch( $request ); |
|
606 | ||
607 | $this->assertErrorResponse( 'rest_cannot_create_user', $response, 403 ); |
|
608 | } |
|
609 | ||
610 | public function test_create_user_invalid_id() { |
|
611 | $this->allow_user_to_manage_multisite(); |
|
@@ 610-627 (lines=18) @@ | ||
607 | $this->assertErrorResponse( 'rest_cannot_create_user', $response, 403 ); |
|
608 | } |
|
609 | ||
610 | public function test_create_user_invalid_id() { |
|
611 | $this->allow_user_to_manage_multisite(); |
|
612 | wp_set_current_user( $this->user ); |
|
613 | ||
614 | $params = array( |
|
615 | 'id' => '156', |
|
616 | 'username' => 'lisasimpson', |
|
617 | 'password' => 'DavidHasselhoff', |
|
618 | 'email' => '[email protected]', |
|
619 | ); |
|
620 | ||
621 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
|
622 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
623 | $request->set_body_params( $params ); |
|
624 | $response = $this->server->dispatch( $request ); |
|
625 | ||
626 | $this->assertErrorResponse( 'rest_user_exists', $response, 400 ); |
|
627 | } |
|
628 | ||
629 | public function test_create_user_invalid_email() { |
|
630 | $this->allow_user_to_manage_multisite(); |
|
@@ 629-645 (lines=17) @@ | ||
626 | $this->assertErrorResponse( 'rest_user_exists', $response, 400 ); |
|
627 | } |
|
628 | ||
629 | public function test_create_user_invalid_email() { |
|
630 | $this->allow_user_to_manage_multisite(); |
|
631 | wp_set_current_user( $this->user ); |
|
632 | ||
633 | $params = array( |
|
634 | 'username' => 'lisasimpson', |
|
635 | 'password' => 'DavidHasselhoff', |
|
636 | 'email' => 'something', |
|
637 | ); |
|
638 | ||
639 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
|
640 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
641 | $request->set_body_params( $params ); |
|
642 | $response = $this->server->dispatch( $request ); |
|
643 | ||
644 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
645 | } |
|
646 | ||
647 | public function test_create_user_invalid_role() { |
|
648 | $this->allow_user_to_manage_multisite(); |
|
@@ 647-664 (lines=18) @@ | ||
644 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
645 | } |
|
646 | ||
647 | public function test_create_user_invalid_role() { |
|
648 | $this->allow_user_to_manage_multisite(); |
|
649 | wp_set_current_user( $this->user ); |
|
650 | ||
651 | $params = array( |
|
652 | 'username' => 'maggiesimpson', |
|
653 | 'password' => 'i_shot_mrburns', |
|
654 | 'email' => '[email protected]', |
|
655 | 'roles' => array( 'baby' ), |
|
656 | ); |
|
657 | ||
658 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
|
659 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
660 | $request->set_body_params( $params ); |
|
661 | $response = $this->server->dispatch( $request ); |
|
662 | ||
663 | $this->assertErrorResponse( 'rest_user_invalid_role', $response, 400 ); |
|
664 | } |
|
665 | ||
666 | public function test_update_item() { |
|
667 | $user_id = $this->factory->user->create( array( |
|
@@ 875-890 (lines=16) @@ | ||
872 | $this->assertArrayNotHasKey( 'BeSharp', $user->caps ); |
|
873 | } |
|
874 | ||
875 | public function test_update_user_without_permission() { |
|
876 | wp_set_current_user( $this->editor ); |
|
877 | ||
878 | $params = array( |
|
879 | 'username' => 'homersimpson', |
|
880 | 'password' => 'stupidsexyflanders', |
|
881 | 'email' => '[email protected]', |
|
882 | ); |
|
883 | ||
884 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $this->user ) ); |
|
885 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
886 | $request->set_body_params( $params ); |
|
887 | $response = $this->server->dispatch( $request ); |
|
888 | ||
889 | $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); |
|
890 | } |
|
891 | ||
892 | public function test_update_user_invalid_id() { |
|
893 | $this->allow_user_to_manage_multisite(); |
|
@@ 892-909 (lines=18) @@ | ||
889 | $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); |
|
890 | } |
|
891 | ||
892 | public function test_update_user_invalid_id() { |
|
893 | $this->allow_user_to_manage_multisite(); |
|
894 | wp_set_current_user( $this->user ); |
|
895 | ||
896 | $params = array( |
|
897 | 'id' => '156', |
|
898 | 'username' => 'lisasimpson', |
|
899 | 'password' => 'DavidHasselhoff', |
|
900 | 'email' => '[email protected]', |
|
901 | ); |
|
902 | ||
903 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $this->editor ) ); |
|
904 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
|
905 | $request->set_body_params( $params ); |
|
906 | $response = $this->server->dispatch( $request ); |
|
907 | ||
908 | $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); |
|
909 | } |
|
910 | ||
911 | public function test_delete_item() { |
|
912 | $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); |
@@ 624-642 (lines=19) @@ | ||
621 | $this->assertEquals( $this->post_id, $data['post'] ); |
|
622 | } |
|
623 | ||
624 | public function test_create_item_invalid_date() { |
|
625 | wp_set_current_user( 0 ); |
|
626 | ||
627 | $params = array( |
|
628 | 'post' => $this->post_id, |
|
629 | 'author_name' => 'Reverend Lovejoy', |
|
630 | 'author_email' => '[email protected]', |
|
631 | 'author_url' => 'http://timothylovejoy.jr', |
|
632 | 'content' => "It\'s all over\, people! We don\'t have a prayer!", |
|
633 | 'date' => rand_str(), |
|
634 | ); |
|
635 | ||
636 | $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); |
|
637 | $request->add_header( 'content-type', 'application/json' ); |
|
638 | $request->set_body( wp_json_encode( $params ) ); |
|
639 | ||
640 | $response = $this->server->dispatch( $request ); |
|
641 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
642 | } |
|
643 | ||
644 | public function test_create_item_assign_different_user() { |
|
645 | $subscriber_id = $this->factory->user->create( array( |
|
@@ 849-866 (lines=18) @@ | ||
846 | $this->assertEquals( '139.130.4.5', $data['author_ip'] ); |
|
847 | } |
|
848 | ||
849 | public function test_create_comment_invalid_author_IP() { |
|
850 | wp_set_current_user( $this->admin_id ); |
|
851 | ||
852 | $params = array( |
|
853 | 'author_name' => 'Comic Book Guy', |
|
854 | 'author_email' => '[email protected]', |
|
855 | 'author_url' => 'http://androidsdungeon.com', |
|
856 | 'author_ip' => '867.5309', |
|
857 | 'content' => 'Worst Comment Ever!', |
|
858 | 'status' => 'approved', |
|
859 | ); |
|
860 | $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); |
|
861 | $request->add_header( 'content-type', 'application/json' ); |
|
862 | $request->set_body( wp_json_encode( $params ) ); |
|
863 | ||
864 | $response = $this->server->dispatch( $request ); |
|
865 | ||
866 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
867 | } |
|
868 | ||
869 | public function test_create_comment_no_post_id() { |
|
@@ 869-885 (lines=17) @@ | ||
866 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
867 | } |
|
868 | ||
869 | public function test_create_comment_no_post_id() { |
|
870 | wp_set_current_user( $this->admin_id ); |
|
871 | ||
872 | $params = array( |
|
873 | 'author_name' => 'Comic Book Guy', |
|
874 | 'author_email' => '[email protected]', |
|
875 | 'author_url' => 'http://androidsdungeon.com', |
|
876 | 'content' => 'Worst Comment Ever!', |
|
877 | 'status' => 'approved', |
|
878 | ); |
|
879 | $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); |
|
880 | $request->add_header( 'content-type', 'application/json' ); |
|
881 | $request->set_body( wp_json_encode( $params ) ); |
|
882 | ||
883 | $response = $this->server->dispatch( $request ); |
|
884 | $this->assertEquals( 201, $response->get_status() ); |
|
885 | } |
|
886 | ||
887 | public function test_create_item_duplicate() { |
|
888 | $this->markTestSkipped( 'Needs to be revisited after wp_die handling is added' ); |