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

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