Code Duplication    Length = 25-25 lines in 3 locations

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

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