Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2147-2197 (lines=51) @@
2144
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2145
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2146
     */
2147
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2148
    {
2149
        $repository = $this->getRepository();
2150
        $locationService = $repository->getLocationService();
2151
2152
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2153
2154
        // Load expected properties before move
2155
        $expected = $this->loadLocationProperties($newParentLocation);
2156
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2157
2158
        $mediaLocationId = $this->generateId('location', 43);
2159
        $demoDesignLocationId = $this->generateId('location', 56);
2160
        /* BEGIN: Use Case */
2161
        // $mediaLocationId is the ID of the "Media" page location in
2162
        // an eZ Publish demo installation
2163
2164
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2165
        // Publish demo installation
2166
2167
        // Load the location service
2168
        $locationService = $repository->getLocationService();
2169
2170
        // Load location to move
2171
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2172
2173
        // Load new parent location
2174
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2175
2176
        // Move location from "Home" to "Demo Design"
2177
        $locationService->moveSubtree(
2178
            $locationToMove,
2179
            $newParentLocation
2180
        );
2181
2182
        // Load moved location
2183
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2184
2185
        // Reload new parent location
2186
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2187
        /* END: Use Case */
2188
2189
        $this->refreshSearch($repository);
2190
2191
        // Load Subtree properties after move
2192
        $actual = $this->loadLocationProperties($newParentLocation);
2193
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2194
2195
        $this->assertEquals($expected, $actual);
2196
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2197
    }
2198
2199
    /**
2200
     * Test for the moveSubtree() method.
@@ 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 testMoveSubtreeDecrementsChildCountOfOldParent()
2206
    {
2207
        $repository = $this->getRepository();
2208
        $locationService = $repository->getLocationService();
2209
2210
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2211
2212
        // Load expected properties before move
2213
        $expected = $this->loadLocationProperties($oldParentLocation);
2214
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
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
        // Get the location id of the old parent
2232
        $oldParentLocationId = $locationToMove->parentLocationId;
2233
2234
        // Load new parent location
2235
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2236
2237
        // Move location from "Home" to "Demo Design"
2238
        $locationService->moveSubtree(
2239
            $locationToMove,
2240
            $newParentLocation
2241
        );
2242
2243
        // Reload old parent location
2244
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2245
        /* END: Use Case */
2246
2247
        $this->refreshSearch($repository);
2248
2249
        // Load Subtree properties after move
2250
        $actual = $this->loadLocationProperties($oldParentLocation);
2251
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2252
2253
        $this->assertEquals($expected, $actual);
2254
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2255
    }
2256
2257
    /**
2258
     * Test moving invisible (hidden by parent) subtree.