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

@@ 1021-1040 (lines=20) @@
1018
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1019
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1020
     */
1021
    public function testUpdateLocationThrowsInvalidArgumentException()
1022
    {
1023
        $repository = $this->getRepository();
1024
1025
        $locationId = $this->generateId('location', 5);
1026
        /* BEGIN: Use Case */
1027
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1028
        $locationService = $repository->getLocationService();
1029
1030
        $originalLocation = $locationService->loadLocation($locationId);
1031
1032
        $updateStruct = $locationService->newLocationUpdateStruct();
1033
1034
        // Remote ID of an existing location with a different locationId
1035
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1036
1037
        // Throws exception, since remote ID is already taken
1038
        $locationService->updateLocation($originalLocation, $updateStruct);
1039
        /* END: Use Case */
1040
    }
1041
1042
    /**
1043
     * Test for the updateLocation() method.
@@ 1884-1910 (lines=27) @@
1881
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1882
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
1883
     */
1884
    public function testCopySubtreeThrowsInvalidArgumentException()
1885
    {
1886
        $repository = $this->getRepository();
1887
1888
        $communityLocationId = $this->generateId('location', 5);
1889
        /* BEGIN: Use Case */
1890
        // $communityLocationId is the ID of the "Community" page location in
1891
        // an eZ Publish demo installation
1892
1893
        // Load the location service
1894
        $locationService = $repository->getLocationService();
1895
1896
        // Load location to copy
1897
        $locationToCopy = $locationService->loadLocation($communityLocationId);
1898
1899
        // Use a child as new parent
1900
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
1901
        $newParentLocation = end($childLocations);
1902
1903
        // This call will fail with an "InvalidArgumentException", because the
1904
        // new parent is a child location of the subtree to copy.
1905
        $locationService->copySubtree(
1906
            $locationToCopy,
1907
            $newParentLocation
1908
        );
1909
        /* END: Use Case */
1910
    }
1911
1912
    /**
1913
     * Test for the moveSubtree() method.
@@ 2304-2332 (lines=29) @@
2301
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2302
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2303
     */
2304
    public function testMoveSubtreeThrowsInvalidArgumentException()
2305
    {
2306
        $repository = $this->getRepository();
2307
        $mediaLocationId = $this->generateId('location', 43);
2308
        $multimediaLocationId = $this->generateId('location', 53);
2309
2310
        /* BEGIN: Use Case */
2311
        // $mediaLocationId is the ID of the "Media" page location in
2312
        // an eZ Publish demo installation
2313
2314
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2315
        // Publish demo installation
2316
2317
        // Load the location service
2318
        $locationService = $repository->getLocationService();
2319
2320
        // Load location to move
2321
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2322
2323
        // Load new parent location
2324
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2325
2326
        // Throws an exception because new parent location is placed below location to move
2327
        $locationService->moveSubtree(
2328
            $locationToMove,
2329
            $newParentLocation
2330
        );
2331
        /* END: Use Case */
2332
    }
2333
2334
    /**
2335
     * 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