Code Duplication    Length = 25-25 lines in 3 locations

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

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