Code Duplication    Length = 11-16 lines in 4 locations

tests/phpunit/tests/rest-api/rest-attachments-controller.php 2 locations

@@ 737-748 (lines=12) @@
734
        $this->assertErrorResponse('rest_invalid_param', $response, 400);
735
    }
736
737
    public function test_create_item_alt_text() 
738
    {
739
        wp_set_current_user(self::$author_id);
740
        $request = new WP_REST_Request('POST', '/wp/v2/media');
741
        $request->set_header('Content-Type', 'image/jpeg');
742
        $request->set_header('Content-Disposition', 'attachment; filename=canola.jpg');
743
744
        $request->set_body(file_get_contents($this->test_file));
745
        $request->set_param('alt_text', 'test alt text');
746
        $response = $this->server->dispatch($request);
747
        $attachment = $response->get_data();
748
        $this->assertEquals('test alt text', $attachment['alt_text']);
749
    }
750
751
    public function test_create_item_unsafe_alt_text() 
@@ 751-761 (lines=11) @@
748
        $this->assertEquals('test alt text', $attachment['alt_text']);
749
    }
750
751
    public function test_create_item_unsafe_alt_text() 
752
    {
753
        wp_set_current_user(self::$author_id);
754
        $request = new WP_REST_Request('POST', '/wp/v2/media');
755
        $request->set_header('Content-Type', 'image/jpeg');
756
        $request->set_header('Content-Disposition', 'attachment; filename=canola.jpg');
757
        $request->set_body(file_get_contents($this->test_file));
758
        $request->set_param('alt_text', '<script>alert(document.cookie)</script>');
759
        $response = $this->server->dispatch($request);
760
        $attachment = $response->get_data();
761
        $this->assertEquals('', $attachment['alt_text']);
762
    }
763
764
    public function test_update_item() 

tests/phpunit/tests/rest-api/rest-users-controller.php 2 locations

@@ 147-162 (lines=16) @@
144
        $this->check_user_data($userdata, $data, 'edit', $data['_links']);
145
    }
146
147
    public function test_get_items_with_edit_context_without_permission() 
148
    {
149
        //test with a user not logged in
150
        $request = new WP_REST_Request('GET', '/wp/v2/users');
151
        $request->set_param('context', 'edit');
152
        $response = $this->server->dispatch($request);
153
154
        $this->assertEquals(401, $response->get_status());
155
156
        //test with a user logged in but without sufficient capabilities; capability in question: 'list_users'
157
        wp_set_current_user(self::$editor);
158
        $request = new WP_REST_Request('GET', '/wp/v2/users');
159
        $request->set_param('context', 'edit');
160
        $response = $this->server->dispatch($request);
161
162
        $this->assertEquals(403, $response->get_status());
163
    }
164
165
    public function test_get_items_unauthenticated_only_shows_public_users() 
@@ 1540-1553 (lines=14) @@
1537
        $this->assertErrorResponse('rest_user_invalid_id', $response, 404);
1538
    }
1539
1540
    public function test_update_item_invalid_password() 
1541
    {
1542
        $this->allow_user_to_manage_multisite();
1543
        wp_set_current_user(self::$user);
1544
1545
        $request = new WP_REST_Request('PUT', sprintf('/wp/v2/users/%d', self::$editor));
1546
1547
        $request->set_param('password', 'no\\backslashes\\allowed');
1548
        $response = $this->server->dispatch($request);
1549
        $this->assertErrorResponse('rest_invalid_param', $response, 400);
1550
1551
        $request->set_param('password', '');
1552
        $response = $this->server->dispatch($request);
1553
        $this->assertErrorResponse('rest_invalid_param', $response, 400);
1554
    }
1555
1556
    public function verify_user_roundtrip( $input = array(), $expected_output = array() )