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

@@ 1967-1994 (lines=28) @@
1964
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
1965
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
1966
     */
1967
    public function testRemoveRoleAssignment()
1968
    {
1969
        $repository = $this->getRepository();
1970
        $roleService = $repository->getRoleService();
1971
1972
        /* BEGIN: Use Case */
1973
        $user = $this->createUserVersion1();
1974
1975
        // Load the existing "Member" role
1976
        $role = $roleService->loadRoleByIdentifier('Member');
1977
1978
        // Assign the "Member" role to the newly created user
1979
        $roleService->assignRoleToUser($role, $user);
1980
1981
        // Unassign user from role
1982
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
1983
        foreach ($roleAssignments as $roleAssignment) {
1984
            if ($roleAssignment->role->id === $role->id) {
1985
                $roleService->removeRoleAssignment($roleAssignment);
1986
            }
1987
        }
1988
        // The assignments array will not contain the new role<->user assignment
1989
        $roleAssignments = $roleService->getRoleAssignments($role);
1990
        /* END: Use Case */
1991
1992
        // Members + Editors + Partners
1993
        $this->assertCount(3, $roleAssignments);
1994
    }
1995
1996
    /**
1997
     * Test for the getRoleAssignmentsForUser() method.