Code Duplication    Length = 29-32 lines in 2 locations

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.

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

@@ 349-377 (lines=29) @@
346
     * @dataProvider dataProviderForOutOfRangeLocationPriority
347
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
348
     */
349
    public function testCreateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
350
    {
351
        $repository = $this->getRepository();
352
353
        $contentId = $this->generateId('object', 41);
354
        $parentLocationId = $this->generateId('location', 5);
355
        /* BEGIN: Use Case */
356
        // $contentId is the ID of an existing content object
357
        // $parentLocationId is the ID of an existing location
358
        $contentService = $repository->getContentService();
359
        $locationService = $repository->getLocationService();
360
361
        // ContentInfo for "How to use eZ Publish"
362
        $contentInfo = $contentService->loadContentInfo($contentId);
363
364
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
365
        $locationCreate->priority = $priority;
366
        $locationCreate->hidden = true;
367
        $locationCreate->remoteId = 'sindelfingen';
368
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
369
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
370
371
        // Throws exception, since priority is out of range
372
        $locationService->createLocation(
373
            $contentInfo,
374
            $locationCreate
375
        );
376
        /* END: Use Case */
377
    }
378
379
    public function dataProviderForOutOfRangeLocationPriority()
380
    {