Code Duplication    Length = 28-28 lines in 2 locations

eZ/Publish/API/Repository/Tests/RoleServiceAuthorizationTest.php 1 location

@@ 500-527 (lines=28) @@
497
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testRemoveRoleAssignment
498
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
499
     */
500
    public function testRemoveRoleAssignmentThrowsUnauthorizedException()
501
    {
502
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
503
504
        $repository = $this->getRepository();
505
        $roleService = $repository->getRoleService();
506
        $permissionResolver = $repository->getPermissionResolver();
507
508
        /* BEGIN: Use Case */
509
        $user = $this->createUserVersion1();
510
511
        $role = $this->createRole();
512
513
        // Assign new role to "Editor" user
514
        $roleService->assignRoleToUser($role, $user);
515
516
        // Set "Editor" user as current user.
517
        $permissionResolver->setCurrentUserReference($user);
518
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
519
520
        // This call will fail with an "UnauthorizedException"
521
        foreach ($roleAssignments as $roleAssignment) {
522
            if ($roleAssignment->role->id === $role->id) {
523
                $roleService->removeRoleAssignment($roleAssignment);
524
            }
525
        }
526
        /* END: Use Case */
527
    }
528
529
    /**
530
     * Test for the getRoleAssignments() method.

eZ/Publish/API/Repository/Tests/RoleServiceTest.php 1 location

@@ 2104-2131 (lines=28) @@
2101
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
2102
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2103
     */
2104
    public function testRemoveRoleAssignment()
2105
    {
2106
        $repository = $this->getRepository();
2107
        $roleService = $repository->getRoleService();
2108
2109
        /* BEGIN: Use Case */
2110
        $user = $this->createUserVersion1();
2111
2112
        // Load the existing "Member" role
2113
        $role = $roleService->loadRoleByIdentifier('Member');
2114
2115
        // Assign the "Member" role to the newly created user
2116
        $roleService->assignRoleToUser($role, $user);
2117
2118
        // Unassign user from role
2119
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2120
        foreach ($roleAssignments as $roleAssignment) {
2121
            if ($roleAssignment->role->id === $role->id) {
2122
                $roleService->removeRoleAssignment($roleAssignment);
2123
            }
2124
        }
2125
        // The assignments array will not contain the new role<->user assignment
2126
        $roleAssignments = $roleService->getRoleAssignments($role);
2127
        /* END: Use Case */
2128
2129
        // Members + Editors + Partners
2130
        $this->assertCount(3, $roleAssignments);
2131
    }
2132
2133
    /**
2134
     * Test for the getRoleAssignmentsForUser() method.