Code Duplication    Length = 20-29 lines in 5 locations

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

@@ 257-279 (lines=23) @@
254
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
255
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
256
     */
257
    public function testUnhideLocationThrowsUnauthorizedException()
258
    {
259
        $repository = $this->getRepository();
260
261
        $editorsGroupId = $this->generateId('group', 13);
262
263
        /* BEGIN: Use Case */
264
        $user = $this->createUserVersion1();
265
266
        $locationService = $repository->getLocationService();
267
268
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
269
270
        // Hide location
271
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
272
273
        // Set current user to newly created user
274
        $repository->setCurrentUser($user);
275
276
        // This call will fail with an "UnauthorizedException"
277
        $locationService->unhideLocation($hiddenLocation);
278
        /* END: Use Case */
279
    }
280
281
    /**
282
     * Test for the deleteLocation() method.

eZ/Publish/API/Repository/Tests/LocationServiceTest.php 4 locations

@@ 1144-1163 (lines=20) @@
1141
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1142
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1143
     */
1144
    public function testUpdateLocationThrowsInvalidArgumentException()
1145
    {
1146
        $repository = $this->getRepository();
1147
1148
        $locationId = $this->generateId('location', 5);
1149
        /* BEGIN: Use Case */
1150
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1151
        $locationService = $repository->getLocationService();
1152
1153
        $originalLocation = $locationService->loadLocation($locationId);
1154
1155
        $updateStruct = $locationService->newLocationUpdateStruct();
1156
1157
        // Remote ID of an existing location with a different locationId
1158
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1159
1160
        // Throws exception, since remote ID is already taken
1161
        $locationService->updateLocation($originalLocation, $updateStruct);
1162
        /* END: Use Case */
1163
    }
1164
1165
    /**
1166
     * Test for the updateLocation() method.
@@ 1173-1192 (lines=20) @@
1170
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1171
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1172
     */
1173
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1174
    {
1175
        $repository = $this->getRepository();
1176
1177
        $locationId = $this->generateId('location', 5);
1178
        /* BEGIN: Use Case */
1179
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1180
        $locationService = $repository->getLocationService();
1181
1182
        $originalLocation = $locationService->loadLocation($locationId);
1183
1184
        $updateStruct = $locationService->newLocationUpdateStruct();
1185
1186
        // Priority value is out of range
1187
        $updateStruct->priority = $priority;
1188
1189
        // Throws exception, since remote ID is already taken
1190
        $locationService->updateLocation($originalLocation, $updateStruct);
1191
        /* END: Use Case */
1192
    }
1193
1194
    /**
1195
     * Test for the updateLocation() method.
@@ 1874-1900 (lines=27) @@
1871
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1872
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
1873
     */
1874
    public function testCopySubtreeThrowsInvalidArgumentException()
1875
    {
1876
        $repository = $this->getRepository();
1877
1878
        $communityLocationId = $this->generateId('location', 5);
1879
        /* BEGIN: Use Case */
1880
        // $communityLocationId is the ID of the "Community" page location in
1881
        // an eZ Publish demo installation
1882
1883
        // Load the location service
1884
        $locationService = $repository->getLocationService();
1885
1886
        // Load location to copy
1887
        $locationToCopy = $locationService->loadLocation($communityLocationId);
1888
1889
        // Use a child as new parent
1890
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
1891
        $newParentLocation = end($childLocations);
1892
1893
        // This call will fail with an "InvalidArgumentException", because the
1894
        // new parent is a child location of the subtree to copy.
1895
        $locationService->copySubtree(
1896
            $locationToCopy,
1897
            $newParentLocation
1898
        );
1899
        /* END: Use Case */
1900
    }
1901
1902
    /**
1903
     * Test for the moveSubtree() method.
@@ 2253-2281 (lines=29) @@
2250
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2251
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2252
     */
2253
    public function testMoveSubtreeThrowsInvalidArgumentException()
2254
    {
2255
        $repository = $this->getRepository();
2256
        $mediaLocationId = $this->generateId('location', 43);
2257
        $multimediaLocationId = $this->generateId('location', 53);
2258
2259
        /* BEGIN: Use Case */
2260
        // $mediaLocationId is the ID of the "Media" page location in
2261
        // an eZ Publish demo installation
2262
2263
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2264
        // Publish demo installation
2265
2266
        // Load the location service
2267
        $locationService = $repository->getLocationService();
2268
2269
        // Load location to move
2270
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2271
2272
        // Load new parent location
2273
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2274
2275
        // Throws an exception because new parent location is placed below location to move
2276
        $locationService->moveSubtree(
2277
            $locationToMove,
2278
            $newParentLocation
2279
        );
2280
        /* END: Use Case */
2281
    }
2282
2283
    /**
2284
     * Loads properties from all locations in the $location's subtree.