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

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