Code Duplication    Length = 20-26 lines in 6 locations

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

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

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/UserServiceTest.php 3 locations

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