Code Duplication    Length = 20-26 lines in 6 locations

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

@@ 570-592 (lines=23) @@
567
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignmentsForUserGroup
568
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
569
     */
570
    public function testGetRoleAssignmentsForUserGroupThrowsUnauthorizedException()
571
    {
572
        $repository = $this->getRepository();
573
        $roleService = $repository->getRoleService();
574
        $userService = $repository->getUserService();
575
576
        $editorsGroupId = $this->generateId('group', 13);
577
578
        /* BEGIN: Use Case */
579
        $user = $this->createUserVersion1();
580
581
        $this->createRole();
582
583
        // Load the "Editors" user group
584
        $userGroup = $userService->loadUserGroup($editorsGroupId);
585
586
        // Set "Editor" user as current user.
587
        $repository->setCurrentUser($user);
588
589
        // This call will fail with an "UnauthorizedException"
590
        $roleService->getRoleAssignmentsForUserGroup($userGroup);
591
        /* END: Use Case */
592
    }
593
594
    /**
595
     * Create a role fixture in a variable named <b>$role</b>,.

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

@@ 134-157 (lines=24) @@
131
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
132
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testMoveUserGroup
133
     */
134
    public function testMoveUserGroupThrowsUnauthorizedException()
135
    {
136
        $repository = $this->getRepository();
137
        $userService = $repository->getUserService();
138
139
        $memberGroupId = $this->generateId('group', 11);
140
        /* BEGIN: Use Case */
141
        // $memberGroupId is the ID of the "Members" group in an eZ Publish
142
        // demo installation
143
        //
144
        $user = $this->createUserVersion1();
145
146
        $userGroup = $this->createUserGroupVersion1();
147
148
        // Load new parent user group
149
        $newParentUserGroup = $userService->loadUserGroup($memberGroupId);
150
151
        // Now set the currently created "Editor" as current user
152
        $repository->setCurrentUser($user);
153
154
        // This call will fail with an "UnauthorizedException"
155
        $userService->moveUserGroup($userGroup, $newParentUserGroup);
156
        /* END: Use Case */
157
    }
158
159
    /**
160
     * Test for the updateUserGroup() method.

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

@@ 150-169 (lines=20) @@
147
     * @see \eZ\Publish\API\Repository\TrashService::trash()
148
     * @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testTrash
149
     */
150
    public function testTrashDecrementsChildCountOnParentLocation()
151
    {
152
        $repository = $this->getRepository();
153
        $locationService = $repository->getLocationService();
154
155
        $baseLocationId = $this->generateId('location', 1);
156
157
        $location = $locationService->loadLocation($baseLocationId);
158
159
        $childCount = $locationService->getLocationChildCount($location);
160
161
        $this->createTrashItem();
162
163
        $this->refreshSearch($repository);
164
165
        $this->assertEquals(
166
            $childCount - 1,
167
            $locationService->getLocationChildCount($location)
168
        );
169
    }
170
171
    /**
172
     * Test sending a location to trash updates Content mainLocation.

eZ/Publish/API/Repository/Tests/UserServiceTest.php 3 locations

@@ 274-293 (lines=20) @@
271
     * @see \eZ\Publish\API\Repository\UserService::createUserGroup()
272
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup
273
     */
274
    public function testCreateUserGroupIncrementsParentSubGroupCount()
275
    {
276
        $repository = $this->getRepository();
277
        $userService = $repository->getUserService();
278
        $mainGroupId = $this->generateId('group', 4);
279
280
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
281
        $parentGroupCount = $parentUserGroup->subGroupCount;
282
283
        /* BEGIN: Use Case */
284
        $this->createUserGroupVersion1();
285
286
        $this->refreshSearch($repository);
287
288
        // This should be one greater than before
289
        $subGroupCount = $userService->loadUserGroup($mainGroupId)->subGroupCount;
290
        /* END: Use Case */
291
292
        $this->assertEquals($parentGroupCount + 1, $subGroupCount);
293
    }
294
295
    /**
296
     * Test for the createUserGroup() method.
@@ 547-572 (lines=26) @@
544
     * @see \eZ\Publish\API\Repository\UserService::moveUserGroup()
545
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testMoveUserGroup
546
     */
547
    public function testMoveUserGroupIncrementsSubGroupCountOnNewParent()
548
    {
549
        $repository = $this->getRepository();
550
        $userService = $repository->getUserService();
551
552
        $membersGroupId = $this->generateId('group', 13);
553
        /* BEGIN: Use Case */
554
        // $membersGroupId is the ID of the "Members" user group in an eZ
555
        // Publish demo installation
556
557
        $userGroup = $this->createUserGroupVersion1();
558
559
        // Load the new parent group
560
        $membersUserGroup = $userService->loadUserGroup($membersGroupId);
561
562
        // Move user group from "Users" to "Members"
563
        $userService->moveUserGroup($userGroup, $membersUserGroup);
564
565
        $this->refreshSearch($repository);
566
567
        // Reload the user group to get an updated $subGroupCount
568
        $membersUserGroupUpdated = $userService->loadUserGroup($membersGroupId);
569
        /* END: Use Case */
570
571
        $this->assertEquals(1, $membersUserGroupUpdated->subGroupCount);
572
    }
573
574
    /**
575
     * Test for the moveUserGroup() method.
@@ 580-602 (lines=23) @@
577
     * @see \eZ\Publish\API\Repository\UserService::moveUserGroup()
578
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testMoveUserGroup
579
     */
580
    public function testMoveUserGroupDecrementsSubGroupCountOnOldParent()
581
    {
582
        $repository = $this->getRepository();
583
        $userService = $repository->getUserService();
584
585
        $membersGroupId = $this->generateId('group', 13);
586
        /* BEGIN: Use Case */
587
        // $membersGroupId is the ID of the "Members" user group in an eZ
588
        // Publish demo installation
589
590
        $userGroup = $this->createUserGroupVersion1();
591
592
        // Load the new parent group
593
        $membersUserGroup = $userService->loadUserGroup($membersGroupId);
594
595
        // Move user group from "Users" to "Members"
596
        $userService->moveUserGroup($userGroup, $membersUserGroup);
597
        /* END: Use Case */
598
599
        $mainUserGroup = $userService->loadUserGroup($this->generateId('group', 4));
600
601
        $this->assertEquals(5, $mainUserGroup->subGroupCount);
602
    }
603
604
    /**
605
     * Test moving a user group below another group throws NotFoundException.