Code Duplication    Length = 31-32 lines in 2 locations

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

@@ 240-271 (lines=32) @@
237
     * @see \eZ\Publish\API\Repository\LocationService::updateLocation()
238
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation
239
     */
240
    public function testUpdateLocationThrowsUnauthorizedException()
241
    {
242
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
243
244
        $repository = $this->getRepository();
245
        $permissionResolver = $repository->getPermissionResolver();
246
247
        $editorsGroupId = $this->generateId('group', 13);
248
249
        /* BEGIN: Use Case */
250
        $user = $this->createUserVersion1();
251
252
        $locationService = $repository->getLocationService();
253
254
        $originalLocation = $locationService->loadLocation($editorsGroupId);
255
256
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
257
        $locationUpdateStruct->priority = 3;
258
        $locationUpdateStruct->remoteId = 'c7adcbf1e96bc29bca28c2d809d0c7ef69272651';
259
        $locationUpdateStruct->sortField = Location::SORT_FIELD_PRIORITY;
260
        $locationUpdateStruct->sortOrder = Location::SORT_ORDER_DESC;
261
262
        // Set current user to newly created user
263
        $permissionResolver->setCurrentUserReference($user);
264
265
        // This call will fail with an "UnauthorizedException"
266
        $locationService->updateLocation(
267
            $originalLocation,
268
            $locationUpdateStruct
269
        );
270
        /* END: Use Case */
271
    }
272
273
    /**
274
     * Test for the swapLocation() method.

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

@@ 271-301 (lines=31) @@
268
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
269
     * @dataProvider dataProviderForOutOfRangeLocationPriority
270
     */
271
    public function testCreateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
272
    {
273
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
274
275
        $repository = $this->getRepository();
276
277
        $contentId = $this->generateId('object', 41);
278
        $parentLocationId = $this->generateId('location', 5);
279
        /* BEGIN: Use Case */
280
        // $contentId is the ID of an existing content object
281
        // $parentLocationId is the ID of an existing location
282
        $contentService = $repository->getContentService();
283
        $locationService = $repository->getLocationService();
284
285
        // ContentInfo for "How to use eZ Publish"
286
        $contentInfo = $contentService->loadContentInfo($contentId);
287
288
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
289
        $locationCreate->priority = $priority;
290
        $locationCreate->hidden = true;
291
        $locationCreate->remoteId = 'sindelfingen';
292
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
293
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
294
295
        // Throws exception, since priority is out of range
296
        $locationService->createLocation(
297
            $contentInfo,
298
            $locationCreate
299
        );
300
        /* END: Use Case */
301
    }
302
303
    public function dataProviderForOutOfRangeLocationPriority()
304
    {