Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2229-2279 (lines=51) @@
2226
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2227
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2228
     */
2229
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2230
    {
2231
        $repository = $this->getRepository();
2232
        $locationService = $repository->getLocationService();
2233
2234
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2235
2236
        // Load expected properties before move
2237
        $expected = $this->loadLocationProperties($newParentLocation);
2238
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2239
2240
        $mediaLocationId = $this->generateId('location', 43);
2241
        $demoDesignLocationId = $this->generateId('location', 56);
2242
        /* BEGIN: Use Case */
2243
        // $mediaLocationId is the ID of the "Media" page location in
2244
        // an eZ Publish demo installation
2245
2246
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2247
        // Publish demo installation
2248
2249
        // Load the location service
2250
        $locationService = $repository->getLocationService();
2251
2252
        // Load location to move
2253
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2254
2255
        // Load new parent location
2256
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2257
2258
        // Move location from "Home" to "Demo Design"
2259
        $locationService->moveSubtree(
2260
            $locationToMove,
2261
            $newParentLocation
2262
        );
2263
2264
        // Load moved location
2265
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2266
2267
        // Reload new parent location
2268
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2269
        /* END: Use Case */
2270
2271
        $this->refreshSearch($repository);
2272
2273
        // Load Subtree properties after move
2274
        $actual = $this->loadLocationProperties($newParentLocation);
2275
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2276
2277
        $this->assertEquals($expected, $actual);
2278
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2279
    }
2280
2281
    /**
2282
     * Test for the moveSubtree() method.
@@ 2287-2337 (lines=51) @@
2284
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2285
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2286
     */
2287
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2288
    {
2289
        $repository = $this->getRepository();
2290
        $locationService = $repository->getLocationService();
2291
2292
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2293
2294
        // Load expected properties before move
2295
        $expected = $this->loadLocationProperties($oldParentLocation);
2296
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2297
2298
        $mediaLocationId = $this->generateId('location', 43);
2299
        $demoDesignLocationId = $this->generateId('location', 56);
2300
        /* BEGIN: Use Case */
2301
        // $mediaLocationId is the ID of the "Media" page location in
2302
        // an eZ Publish demo installation
2303
2304
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2305
        // Publish demo installation
2306
2307
        // Load the location service
2308
        $locationService = $repository->getLocationService();
2309
2310
        // Load location to move
2311
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2312
2313
        // Get the location id of the old parent
2314
        $oldParentLocationId = $locationToMove->parentLocationId;
2315
2316
        // Load new parent location
2317
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2318
2319
        // Move location from "Home" to "Demo Design"
2320
        $locationService->moveSubtree(
2321
            $locationToMove,
2322
            $newParentLocation
2323
        );
2324
2325
        // Reload old parent location
2326
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2327
        /* END: Use Case */
2328
2329
        $this->refreshSearch($repository);
2330
2331
        // Load Subtree properties after move
2332
        $actual = $this->loadLocationProperties($oldParentLocation);
2333
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2334
2335
        $this->assertEquals($expected, $actual);
2336
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2337
    }
2338
2339
    /**
2340
     * Test for the moveSubtree() method.