Code Duplication    Length = 29-32 lines in 2 locations

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

@@ 308-336 (lines=29) @@
305
     * @dataProvider dataProviderForOutOfRangeLocationPriority
306
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
307
     */
308
    public function testCreateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
309
    {
310
        $repository = $this->getRepository();
311
312
        $contentId = $this->generateId('object', 41);
313
        $parentLocationId = $this->generateId('location', 5);
314
        /* BEGIN: Use Case */
315
        // $contentId is the ID of an existing content object
316
        // $parentLocationId is the ID of an existing location
317
        $contentService = $repository->getContentService();
318
        $locationService = $repository->getLocationService();
319
320
        // ContentInfo for "How to use eZ Publish"
321
        $contentInfo = $contentService->loadContentInfo($contentId);
322
323
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
324
        $locationCreate->priority = $priority;
325
        $locationCreate->hidden = true;
326
        $locationCreate->remoteId = 'sindelfingen';
327
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
328
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
329
330
        // Throws exception, since priority is out of range
331
        $locationService->createLocation(
332
            $contentInfo,
333
            $locationCreate
334
        );
335
        /* END: Use Case */
336
    }
337
338
    public function dataProviderForOutOfRangeLocationPriority()
339
    {

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

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