Code Duplication    Length = 21-24 lines in 2 locations

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

@@ 1379-1399 (lines=21) @@
1376
        $this->assertArrayNotHasKey('administrator', $user->caps);
1377
    }
1378
1379
    public function test_update_user_role_invalid_privilege_escalation() 
1380
    {
1381
        wp_set_current_user(self::$editor);
1382
1383
        $request = new WP_REST_Request('PUT', sprintf('/wp/v2/users/%d', self::$editor));
1384
        $request->set_param('roles', array( 'administrator' ));
1385
        $response = $this->server->dispatch($request);
1386
1387
        $this->assertErrorResponse('rest_cannot_edit_roles', $response, 403);
1388
        $user = get_userdata(self::$editor);
1389
        $this->assertArrayHasKey('editor', $user->caps);
1390
        $this->assertArrayNotHasKey('administrator', $user->caps);
1391
1392
        $request = new WP_REST_Request('PUT', '/wp/v2/users/me');
1393
        $request->set_param('roles', array( 'administrator' ));
1394
        $response = $this->server->dispatch($request);
1395
1396
        $this->assertErrorResponse('rest_cannot_edit_roles', $response, 403);
1397
        $user = get_userdata(self::$editor);
1398
        $this->assertArrayHasKey('editor', $user->caps);
1399
        $this->assertArrayNotHasKey('administrator', $user->caps);
1400
    }
1401
1402
    public function test_update_user_role_invalid_privilege_deescalation() 
@@ 1469-1492 (lines=24) @@
1466
    }
1467
1468
1469
    public function test_update_user_role_invalid_role() 
1470
    {
1471
        wp_set_current_user(self::$user);
1472
        $this->allow_user_to_manage_multisite();
1473
1474
        $request = new WP_REST_Request('PUT', sprintf('/wp/v2/users/%d', self::$editor));
1475
        $request->set_param('roles', array( 'BeSharp' ));
1476
        $response = $this->server->dispatch($request);
1477
1478
        $this->assertErrorResponse('rest_user_invalid_role', $response, 400);
1479
1480
        $user = get_userdata(self::$editor);
1481
        $this->assertArrayHasKey('editor', $user->caps);
1482
        $this->assertArrayNotHasKey('BeSharp', $user->caps);
1483
1484
        $request = new WP_REST_Request('PUT', '/wp/v2/users/me');
1485
        $request->set_param('roles', array( 'BeSharp' ));
1486
        $response = $this->server->dispatch($request);
1487
1488
        $this->assertErrorResponse('rest_user_invalid_role', $response, 400);
1489
1490
        $user = get_userdata(self::$editor);
1491
        $this->assertArrayHasKey('editor', $user->caps);
1492
        $this->assertArrayNotHasKey('BeSharp', $user->caps);
1493
    }
1494
1495
    public function test_update_user_without_permission()