Code Duplication    Length = 29-32 lines in 2 locations

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

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

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