Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2205-2255 (lines=51) @@
2202
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2203
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2204
     */
2205
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2206
    {
2207
        $repository = $this->getRepository();
2208
        $locationService = $repository->getLocationService();
2209
2210
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2211
2212
        // Load expected properties before move
2213
        $expected = $this->loadLocationProperties($newParentLocation);
2214
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2215
2216
        $mediaLocationId = $this->generateId('location', 43);
2217
        $demoDesignLocationId = $this->generateId('location', 56);
2218
        /* BEGIN: Use Case */
2219
        // $mediaLocationId is the ID of the "Media" page location in
2220
        // an eZ Publish demo installation
2221
2222
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2223
        // Publish demo installation
2224
2225
        // Load the location service
2226
        $locationService = $repository->getLocationService();
2227
2228
        // Load location to move
2229
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2230
2231
        // Load new parent location
2232
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2233
2234
        // Move location from "Home" to "Demo Design"
2235
        $locationService->moveSubtree(
2236
            $locationToMove,
2237
            $newParentLocation
2238
        );
2239
2240
        // Load moved location
2241
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2242
2243
        // Reload new parent location
2244
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2245
        /* END: Use Case */
2246
2247
        $this->refreshSearch($repository);
2248
2249
        // Load Subtree properties after move
2250
        $actual = $this->loadLocationProperties($newParentLocation);
2251
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2252
2253
        $this->assertEquals($expected, $actual);
2254
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2255
    }
2256
2257
    /**
2258
     * Test for the moveSubtree() method.
@@ 2263-2313 (lines=51) @@
2260
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2261
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2262
     */
2263
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2264
    {
2265
        $repository = $this->getRepository();
2266
        $locationService = $repository->getLocationService();
2267
2268
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2269
2270
        // Load expected properties before move
2271
        $expected = $this->loadLocationProperties($oldParentLocation);
2272
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2273
2274
        $mediaLocationId = $this->generateId('location', 43);
2275
        $demoDesignLocationId = $this->generateId('location', 56);
2276
        /* BEGIN: Use Case */
2277
        // $mediaLocationId is the ID of the "Media" page location in
2278
        // an eZ Publish demo installation
2279
2280
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2281
        // Publish demo installation
2282
2283
        // Load the location service
2284
        $locationService = $repository->getLocationService();
2285
2286
        // Load location to move
2287
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2288
2289
        // Get the location id of the old parent
2290
        $oldParentLocationId = $locationToMove->parentLocationId;
2291
2292
        // Load new parent location
2293
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2294
2295
        // Move location from "Home" to "Demo Design"
2296
        $locationService->moveSubtree(
2297
            $locationToMove,
2298
            $newParentLocation
2299
        );
2300
2301
        // Reload old parent location
2302
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2303
        /* END: Use Case */
2304
2305
        $this->refreshSearch($repository);
2306
2307
        // Load Subtree properties after move
2308
        $actual = $this->loadLocationProperties($oldParentLocation);
2309
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2310
2311
        $this->assertEquals($expected, $actual);
2312
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2313
    }
2314
2315
    /**
2316
     * Test for the moveSubtree() method.