Code Duplication    Length = 20-29 lines in 5 locations

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

@@ 316-338 (lines=23) @@
313
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
314
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
315
     */
316
    public function testUnhideLocationThrowsUnauthorizedException()
317
    {
318
        $repository = $this->getRepository();
319
320
        $editorsGroupId = $this->generateId('group', 13);
321
322
        /* BEGIN: Use Case */
323
        $user = $this->createUserVersion1();
324
325
        $locationService = $repository->getLocationService();
326
327
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
328
329
        // Hide location
330
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
331
332
        // Set current user to newly created user
333
        $repository->setCurrentUser($user);
334
335
        // This call will fail with an "UnauthorizedException"
336
        $locationService->unhideLocation($hiddenLocation);
337
        /* END: Use Case */
338
    }
339
340
    /**
341
     * Test for the deleteLocation() method.

eZ/Publish/API/Repository/Tests/LocationServiceTest.php 3 locations

@@ 1103-1122 (lines=20) @@
1100
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1101
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1102
     */
1103
    public function testUpdateLocationThrowsInvalidArgumentException()
1104
    {
1105
        $repository = $this->getRepository();
1106
1107
        $locationId = $this->generateId('location', 5);
1108
        /* BEGIN: Use Case */
1109
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1110
        $locationService = $repository->getLocationService();
1111
1112
        $originalLocation = $locationService->loadLocation($locationId);
1113
1114
        $updateStruct = $locationService->newLocationUpdateStruct();
1115
1116
        // Remote ID of an existing location with a different locationId
1117
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1118
1119
        // Throws exception, since remote ID is already taken
1120
        $locationService->updateLocation($originalLocation, $updateStruct);
1121
        /* END: Use Case */
1122
    }
1123
1124
    /**
1125
     * Test for the updateLocation() method.
@@ 1966-1992 (lines=27) @@
1963
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1964
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
1965
     */
1966
    public function testCopySubtreeThrowsInvalidArgumentException()
1967
    {
1968
        $repository = $this->getRepository();
1969
1970
        $communityLocationId = $this->generateId('location', 5);
1971
        /* BEGIN: Use Case */
1972
        // $communityLocationId is the ID of the "Community" page location in
1973
        // an eZ Publish demo installation
1974
1975
        // Load the location service
1976
        $locationService = $repository->getLocationService();
1977
1978
        // Load location to copy
1979
        $locationToCopy = $locationService->loadLocation($communityLocationId);
1980
1981
        // Use a child as new parent
1982
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
1983
        $newParentLocation = end($childLocations);
1984
1985
        // This call will fail with an "InvalidArgumentException", because the
1986
        // new parent is a child location of the subtree to copy.
1987
        $locationService->copySubtree(
1988
            $locationToCopy,
1989
            $newParentLocation
1990
        );
1991
        /* END: Use Case */
1992
    }
1993
1994
    /**
1995
     * Test for the moveSubtree() method.
@@ 2386-2414 (lines=29) @@
2383
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2384
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2385
     */
2386
    public function testMoveSubtreeThrowsInvalidArgumentException()
2387
    {
2388
        $repository = $this->getRepository();
2389
        $mediaLocationId = $this->generateId('location', 43);
2390
        $multimediaLocationId = $this->generateId('location', 53);
2391
2392
        /* BEGIN: Use Case */
2393
        // $mediaLocationId is the ID of the "Media" page location in
2394
        // an eZ Publish demo installation
2395
2396
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2397
        // Publish demo installation
2398
2399
        // Load the location service
2400
        $locationService = $repository->getLocationService();
2401
2402
        // Load location to move
2403
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2404
2405
        // Load new parent location
2406
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2407
2408
        // Throws an exception because new parent location is placed below location to move
2409
        $locationService->moveSubtree(
2410
            $locationToMove,
2411
            $newParentLocation
2412
        );
2413
        /* END: Use Case */
2414
    }
2415
2416
    /**
2417
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated

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

@@ 72-95 (lines=24) @@
69
     *
70
     * @see \eZ\Publish\API\Repository\URLAliasService::createUrlAlias()
71
     */
72
    public function testCreateUrlAlias()
73
    {
74
        $repository = $this->getRepository();
75
76
        $locationId = $this->generateId('location', 5);
77
78
        /* BEGIN: Use Case */
79
        // $locationId is the ID of an existing location
80
81
        $locationService = $repository->getLocationService();
82
        $urlAliasService = $repository->getURLAliasService();
83
84
        $location = $locationService->loadLocation($locationId);
85
86
        $createdUrlAlias = $urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US');
87
        /* END: Use Case */
88
89
        $this->assertInstanceOf(
90
            'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
91
            $createdUrlAlias
92
        );
93
94
        return [$createdUrlAlias, $location->id];
95
    }
96
97
    /**
98
     * @param array $testData