Code Duplication    Length = 20-26 lines in 6 locations

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

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

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

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

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

@@ 238-257 (lines=20) @@
235
     * @see \eZ\Publish\API\Repository\UserService::createUserGroup()
236
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup
237
     */
238
    public function testCreateUserGroupIncrementsParentSubGroupCount()
239
    {
240
        $repository = $this->getRepository();
241
        $userService = $repository->getUserService();
242
        $mainGroupId = $this->generateId('group', 4);
243
244
        $parentUserGroup = $userService->loadUserGroup($mainGroupId);
245
        $parentGroupCount = $parentUserGroup->subGroupCount;
246
247
        /* BEGIN: Use Case */
248
        $this->createUserGroupVersion1();
249
250
        $this->refreshSearch($repository);
251
252
        // This should be one greater than before
253
        $subGroupCount = $userService->loadUserGroup($mainGroupId)->subGroupCount;
254
        /* END: Use Case */
255
256
        $this->assertEquals($parentGroupCount + 1, $subGroupCount);
257
    }
258
259
    /**
260
     * Test for the createUserGroup() method.
@@ 485-510 (lines=26) @@
482
     * @see \eZ\Publish\API\Repository\UserService::moveUserGroup()
483
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testMoveUserGroup
484
     */
485
    public function testMoveUserGroupIncrementsSubGroupCountOnNewParent()
486
    {
487
        $repository = $this->getRepository();
488
        $userService = $repository->getUserService();
489
490
        $membersGroupId = $this->generateId('group', 13);
491
        /* BEGIN: Use Case */
492
        // $membersGroupId is the ID of the "Members" user group in an eZ
493
        // Publish demo installation
494
495
        $userGroup = $this->createUserGroupVersion1();
496
497
        // Load the new parent group
498
        $membersUserGroup = $userService->loadUserGroup($membersGroupId);
499
500
        // Move user group from "Users" to "Members"
501
        $userService->moveUserGroup($userGroup, $membersUserGroup);
502
503
        $this->refreshSearch($repository);
504
505
        // Reload the user group to get an updated $subGroupCount
506
        $membersUserGroupUpdated = $userService->loadUserGroup($membersGroupId);
507
        /* END: Use Case */
508
509
        $this->assertEquals(1, $membersUserGroupUpdated->subGroupCount);
510
    }
511
512
    /**
513
     * Test for the moveUserGroup() method.
@@ 518-540 (lines=23) @@
515
     * @see \eZ\Publish\API\Repository\UserService::moveUserGroup()
516
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testMoveUserGroup
517
     */
518
    public function testMoveUserGroupDecrementsSubGroupCountOnOldParent()
519
    {
520
        $repository = $this->getRepository();
521
        $userService = $repository->getUserService();
522
523
        $membersGroupId = $this->generateId('group', 13);
524
        /* BEGIN: Use Case */
525
        // $membersGroupId is the ID of the "Members" user group in an eZ
526
        // Publish demo installation
527
528
        $userGroup = $this->createUserGroupVersion1();
529
530
        // Load the new parent group
531
        $membersUserGroup = $userService->loadUserGroup($membersGroupId);
532
533
        // Move user group from "Users" to "Members"
534
        $userService->moveUserGroup($userGroup, $membersUserGroup);
535
        /* END: Use Case */
536
537
        $mainUserGroup = $userService->loadUserGroup($this->generateId('group', 4));
538
539
        $this->assertEquals(5, $mainUserGroup->subGroupCount);
540
    }
541
542
    /**
543
     * Test for the newUserGroupUpdateStruct() method.

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

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