Code Duplication    Length = 25-25 lines in 3 locations

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

@@ 171-195 (lines=25) @@
168
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
169
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
170
     */
171
    public function testCreateLocationThrowsInvalidArgumentExceptionContentAlreadyBelowParent()
172
    {
173
        $repository = $this->getRepository();
174
175
        $contentId = $this->generateId('object', 11);
176
        $parentLocationId = $this->generateId('location', 5);
177
        /* BEGIN: Use Case */
178
        // $contentId is the ID of an existing content object
179
        // $parentLocationId is the ID of an existing location which already
180
        // has the content assigned to one of its descendant locations
181
        $contentService = $repository->getContentService();
182
        $locationService = $repository->getLocationService();
183
184
        // ContentInfo for "How to use eZ Publish"
185
        $contentInfo = $contentService->loadContentInfo($contentId);
186
187
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
188
189
        // Throws exception, since content is already located at "/1/2/107/110/"
190
        $locationService->createLocation(
191
            $contentInfo,
192
            $locationCreate
193
        );
194
        /* END: Use Case */
195
    }
196
197
    /**
198
     * Test for the createLocation() method.
@@ 204-228 (lines=25) @@
201
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
202
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
203
     */
204
    public function testCreateLocationThrowsInvalidArgumentExceptionParentIsSubLocationOfContent()
205
    {
206
        $repository = $this->getRepository();
207
208
        $contentId = $this->generateId('object', 4);
209
        $parentLocationId = $this->generateId('location', 12);
210
        /* BEGIN: Use Case */
211
        // $contentId is the ID of an existing content object
212
        // $parentLocationId is the ID of an existing location which is below a
213
        // location that is assigned to the content
214
        $contentService = $repository->getContentService();
215
        $locationService = $repository->getLocationService();
216
217
        // ContentInfo for "How to use eZ Publish"
218
        $contentInfo = $contentService->loadContentInfo($contentId);
219
220
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
221
222
        // Throws exception, since content is already located at "/1/2/"
223
        $locationService->createLocation(
224
            $contentInfo,
225
            $locationCreate
226
        );
227
        /* END: Use Case */
228
    }
229
230
    /**
231
     * Test for the createLocation() method.
@@ 237-261 (lines=25) @@
234
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
235
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
236
     */
237
    public function testCreateLocationThrowsInvalidArgumentExceptionRemoteIdExists()
238
    {
239
        $repository = $this->getRepository();
240
241
        $contentId = $this->generateId('object', 41);
242
        $parentLocationId = $this->generateId('location', 5);
243
        /* BEGIN: Use Case */
244
        // $contentId is the ID of an existing content object
245
        $contentService = $repository->getContentService();
246
        $locationService = $repository->getLocationService();
247
248
        // ContentInfo for "How to use eZ Publish"
249
        $contentInfo = $contentService->loadContentInfo($contentId);
250
251
        $locationCreate = $locationService->newLocationCreateStruct($parentLocationId);
252
        // This remote ID already exists
253
        $locationCreate->remoteId = 'f3e90596361e31d496d4026eb624c983';
254
255
        // Throws exception, since remote ID is already in use
256
        $locationService->createLocation(
257
            $contentInfo,
258
            $locationCreate
259
        );
260
        /* END: Use Case */
261
    }
262
263
    /**
264
     * Test for the createLocation() method.