Code Duplication    Length = 25-25 lines in 3 locations

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

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