Code Duplication    Length = 31-34 lines in 2 locations

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

@@ 31-64 (lines=34) @@
28
     * @see \eZ\Publish\API\Repository\LocationService::createLocation()
29
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
30
     */
31
    public function testCreateLocationThrowsUnauthorizedException()
32
    {
33
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
34
35
        $repository = $this->getRepository();
36
37
        $editorsGroupId = $this->generateId('group', 13);
38
39
        /* BEGIN: Use Case */
40
        $contentService = $repository->getContentService();
41
        $locationService = $repository->getLocationService();
42
43
        $user = $this->createUserVersion1();
44
45
        // ContentInfo for "Editors" user group
46
        $contentInfo = $contentService->loadContentInfo($editorsGroupId);
47
48
        // Set current user to newly created user
49
        $repository->setCurrentUser($user);
50
51
        $locationCreate = $locationService->newLocationCreateStruct(1);
52
        $locationCreate->priority = 23;
53
        $locationCreate->hidden = true;
54
        $locationCreate->remoteId = 'sindelfingen';
55
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
56
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
57
58
        // This call will fail with an "UnauthorizedException"
59
        $locationService->createLocation(
60
            $contentInfo,
61
            $locationCreate
62
        );
63
        /* END: Use Case */
64
    }
65
66
    /**
67
     * Test for the createLocation() method. Tests a case when user doesn't have content/manage_locations policy for the new location ID.

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
    {