Code Duplication    Length = 23-35 lines in 4 locations

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

@@ 141-168 (lines=28) @@
138
     * @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testRecover
139
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser
140
     */
141
    public function testRecoverThrowsUnauthorizedExceptionWithNewParentLocationParameter()
142
    {
143
        $repository = $this->getRepository();
144
        $trashService = $repository->getTrashService();
145
        $locationService = $repository->getLocationService();
146
147
        $homeLocationId = $this->generateId('location', 2);
148
        $anonymousUserId = $this->generateId('user', 10);
149
        /* BEGIN: Use Case */
150
        // $anonymousUserId is the ID of the "Anonymous" user
151
        // $homeLocationId is the ID of the "Home" location in an eZ Publish
152
        // demo installation
153
154
        $trashItem = $this->createTrashItem();
155
156
        // Get the new parent location
157
        $newParentLocation = $locationService->loadLocation($homeLocationId);
158
159
        // Load user service
160
        $userService = $repository->getUserService();
161
162
        // Set "Anonymous" as current user
163
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
164
165
        // This call will fail with an "UnauthorizedException"
166
        $trashService->recover($trashItem, $newParentLocation);
167
        /* END: Use Case */
168
    }
169
170
    /**
171
     * Test for the emptyTrash() method.

eZ/Publish/API/Repository/Tests/URLAliasServiceAuthorizationTest.php 2 locations

@@ 20-42 (lines=23) @@
17
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
18
     * @depends \eZ\Publish\API\Repository\Tests\URLAliasServiceTest::testCreateUrlAlias
19
     */
20
    public function testCreateUrlAliasThrowsUnauthorizedException()
21
    {
22
        $repository = $this->getRepository();
23
24
        $anonymousUserId = $this->generateId('user', 10);
25
        $parentLocationId = $this->generateId('location', 2);
26
        /* BEGIN: Use Case */
27
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
28
        // Publish demo installation.
29
        // $locationId is the ID of an existing location
30
        $userService = $repository->getUserService();
31
        $urlAliasService = $repository->getURLAliasService();
32
        $locationService = $repository->getLocationService();
33
34
        $location = $locationService->newLocationCreateStruct($parentLocationId);
35
36
        $anonymousUser = $userService->loadUser($anonymousUserId);
37
        $repository->getPermissionResolver()->setCurrentUserReference($anonymousUser);
38
39
        // This call will fail with an UnauthorizedException
40
        $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US');
41
        /* END: Use Case */
42
    }
43
44
    /**
45
     * Test for the createGlobalUrlAlias() method.
@@ 77-102 (lines=26) @@
74
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
75
     * @depends \eZ\Publish\API\Repository\Tests\URLAliasServiceTest::testRemoveAliases
76
     */
77
    public function testRemoveAliasesThrowsUnauthorizedException()
78
    {
79
        $repository = $this->getRepository();
80
        $anonymousUserId = $this->generateId('user', 10);
81
82
        $locationService = $repository->getLocationService();
83
        $someLocation = $locationService->loadLocation(
84
            $this->generateId('location', 12)
85
        );
86
87
        /* BEGIN: Use Case */
88
        // $someLocation contains a location with automatically generated
89
        // aliases assigned
90
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
91
        $urlAliasService = $repository->getURLAliasService();
92
        $userService = $repository->getUserService();
93
94
        $anonymousUser = $userService->loadUser($anonymousUserId);
95
        $repository->getPermissionResolver()->setCurrentUserReference($anonymousUser);
96
97
        $initialAliases = $urlAliasService->listLocationAliases($someLocation);
98
99
        // This call will fail with an UnauthorizedException
100
        $urlAliasService->removeAliases($initialAliases);
101
        /* END: Use Case */
102
    }
103
}
104

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

@@ 803-837 (lines=35) @@
800
     *
801
     * @see \eZ\Publish\API\Repository\URLAliasService::removeAliases()
802
     */
803
    public function testRemoveAliases()
804
    {
805
        $repository = $this->getRepository();
806
807
        $locationService = $repository->getLocationService();
808
        $someLocation = $locationService->loadLocation(
809
            $this->generateId('location', 12)
810
        );
811
812
        /* BEGIN: Use Case */
813
        // $someLocation contains a location with automatically generated
814
        // aliases assigned
815
        $urlAliasService = $repository->getURLAliasService();
816
817
        $initialAliases = $urlAliasService->listLocationAliases($someLocation);
818
819
        // Creates a custom alias for $someLocation
820
        $urlAliasService->createUrlAlias(
821
            $someLocation,
822
            '/my/fancy/url/alias/sindelfingen',
823
            'eng-US'
824
        );
825
826
        $customAliases = $urlAliasService->listLocationAliases($someLocation);
827
828
        // The custom alias just created will be removed
829
        // the automatic aliases stay in tact
830
        $urlAliasService->removeAliases($customAliases);
831
        /* END: Use Case */
832
833
        $this->assertEquals(
834
            $initialAliases,
835
            $urlAliasService->listLocationAliases($someLocation)
836
        );
837
    }
838
839
    /**
840
     * Test for the removeAliases() method.