Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like LocationServiceTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use LocationServiceTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class LocationServiceTest extends BaseTest |
||
27 | { |
||
28 | /** |
||
29 | * Test for the newLocationCreateStruct() method. |
||
30 | * |
||
31 | * @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct |
||
32 | * |
||
33 | * @see \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct() |
||
34 | */ |
||
35 | View Code Duplication | public function testNewLocationCreateStruct() |
|
36 | { |
||
37 | $repository = $this->getRepository(); |
||
38 | |||
39 | $parentLocationId = $this->generateId('location', 1); |
||
40 | /* BEGIN: Use Case */ |
||
41 | // $parentLocationId is the ID of an existing location |
||
42 | $locationService = $repository->getLocationService(); |
||
43 | |||
44 | $locationCreate = $locationService->newLocationCreateStruct( |
||
45 | $parentLocationId |
||
46 | ); |
||
47 | /* END: Use Case */ |
||
48 | |||
49 | $this->assertInstanceOf( |
||
50 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationCreateStruct', |
||
51 | $locationCreate |
||
52 | ); |
||
53 | |||
54 | return $locationCreate; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Test for the newLocationCreateStruct() method. |
||
59 | * |
||
60 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreate |
||
61 | * |
||
62 | * @see \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct() |
||
63 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
64 | */ |
||
65 | public function testNewLocationCreateStructValues(LocationCreateStruct $locationCreate) |
||
66 | { |
||
67 | $this->assertPropertiesCorrect( |
||
68 | array( |
||
69 | 'priority' => 0, |
||
70 | 'hidden' => false, |
||
71 | // remoteId should be initialized with a default value |
||
72 | //'remoteId' => null, |
||
73 | 'sortField' => Location::SORT_FIELD_NAME, |
||
74 | 'sortOrder' => Location::SORT_ORDER_ASC, |
||
75 | 'parentLocationId' => $this->generateId('location', 1), |
||
76 | ), |
||
77 | $locationCreate |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Test for the createLocation() method. |
||
83 | * |
||
84 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
85 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
86 | */ |
||
87 | public function testCreateLocation() |
||
88 | { |
||
89 | $repository = $this->getRepository(); |
||
90 | |||
91 | $contentId = $this->generateId('object', 41); |
||
92 | $parentLocationId = $this->generateId('location', 5); |
||
93 | /* BEGIN: Use Case */ |
||
94 | // $contentId is the ID of an existing content object |
||
95 | // $parentLocationId is the ID of an existing location |
||
96 | $contentService = $repository->getContentService(); |
||
97 | $locationService = $repository->getLocationService(); |
||
98 | |||
99 | // ContentInfo for "How to use eZ Publish" |
||
100 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
101 | |||
102 | $locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
||
103 | $locationCreate->priority = 23; |
||
104 | $locationCreate->hidden = true; |
||
105 | $locationCreate->remoteId = 'sindelfingen'; |
||
106 | $locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
107 | $locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
108 | |||
109 | $location = $locationService->createLocation( |
||
110 | $contentInfo, |
||
111 | $locationCreate |
||
112 | ); |
||
113 | /* END: Use Case */ |
||
114 | |||
115 | $this->assertInstanceOf( |
||
116 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
117 | $location |
||
118 | ); |
||
119 | |||
120 | return array( |
||
121 | 'locationCreate' => $locationCreate, |
||
122 | 'createdLocation' => $location, |
||
123 | 'contentInfo' => $contentInfo, |
||
124 | 'parentLocation' => $locationService->loadLocation($this->generateId('location', 5)), |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Test for the createLocation() method. |
||
130 | * |
||
131 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
132 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
133 | */ |
||
134 | public function testCreateLocationStructValues(array $data) |
||
135 | { |
||
136 | $locationCreate = $data['locationCreate']; |
||
137 | $createdLocation = $data['createdLocation']; |
||
138 | $contentInfo = $data['contentInfo']; |
||
139 | |||
140 | $this->assertPropertiesCorrect( |
||
141 | array( |
||
142 | 'priority' => $locationCreate->priority, |
||
143 | 'hidden' => $locationCreate->hidden, |
||
144 | 'invisible' => $locationCreate->hidden, |
||
145 | 'remoteId' => $locationCreate->remoteId, |
||
146 | 'contentInfo' => $contentInfo, |
||
147 | 'parentLocationId' => $locationCreate->parentLocationId, |
||
148 | 'pathString' => '/1/5/' . $this->parseId('location', $createdLocation->id) . '/', |
||
149 | 'depth' => 2, |
||
150 | 'sortField' => $locationCreate->sortField, |
||
151 | 'sortOrder' => $locationCreate->sortOrder, |
||
152 | ), |
||
153 | $createdLocation |
||
154 | ); |
||
155 | |||
156 | $this->assertNotNull($createdLocation->id); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Test for the createLocation() method. |
||
161 | * |
||
162 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
163 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
164 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
165 | */ |
||
166 | View Code Duplication | 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. |
||
194 | * |
||
195 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
196 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
197 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
198 | */ |
||
199 | View Code Duplication | 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. |
||
227 | * |
||
228 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
229 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
230 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
231 | */ |
||
232 | View Code Duplication | 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. |
||
260 | * |
||
261 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
262 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
263 | */ |
||
264 | public function testCreateLocationInTransactionWithRollback() |
||
265 | { |
||
266 | $repository = $this->getRepository(); |
||
267 | |||
268 | $contentId = $this->generateId('object', 41); |
||
269 | $parentLocationId = $this->generateId('location', 5); |
||
270 | /* BEGIN: Use Case */ |
||
271 | // $contentId is the ID of an existing content object |
||
272 | // $parentLocationId is the ID of an existing location |
||
273 | $contentService = $repository->getContentService(); |
||
274 | $locationService = $repository->getLocationService(); |
||
275 | |||
276 | $repository->beginTransaction(); |
||
277 | |||
278 | try { |
||
279 | // ContentInfo for "How to use eZ Publish" |
||
280 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
281 | |||
282 | $locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
||
283 | $locationCreate->remoteId = 'sindelfingen'; |
||
284 | |||
285 | $createdLocationId = $locationService->createLocation( |
||
286 | $contentInfo, |
||
287 | $locationCreate |
||
288 | )->id; |
||
289 | } catch (Exception $e) { |
||
290 | // Cleanup hanging transaction on error |
||
291 | $repository->rollback(); |
||
292 | throw $e; |
||
293 | } |
||
294 | |||
295 | $repository->rollback(); |
||
296 | |||
297 | try { |
||
298 | // Throws exception since creation of location was rolled back |
||
299 | $location = $locationService->loadLocation($createdLocationId); |
||
|
|||
300 | } catch (NotFoundException $e) { |
||
301 | return; |
||
302 | } |
||
303 | /* END: Use Case */ |
||
304 | |||
305 | $this->fail('Objects still exists after rollback.'); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * Test for the loadLocation() method. |
||
310 | * |
||
311 | * @return \eZ\Publish\API\Repository\Values\Content\Location |
||
312 | * |
||
313 | * @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
||
314 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
315 | */ |
||
316 | View Code Duplication | public function testLoadLocation() |
|
317 | { |
||
318 | $repository = $this->getRepository(); |
||
319 | |||
320 | $locationId = $this->generateId('location', 5); |
||
321 | /* BEGIN: Use Case */ |
||
322 | // $locationId is the ID of an existing location |
||
323 | $locationService = $repository->getLocationService(); |
||
324 | |||
325 | $location = $locationService->loadLocation($locationId); |
||
326 | /* END: Use Case */ |
||
327 | |||
328 | $this->assertInstanceOf( |
||
329 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
330 | $location |
||
331 | ); |
||
332 | |||
333 | return $location; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * Test for the loadLocation() method. |
||
338 | * |
||
339 | * @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
||
340 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
341 | */ |
||
342 | public function testLoadLocationRootStructValues() |
||
343 | { |
||
344 | $repository = $this->getRepository(); |
||
345 | $locationService = $repository->getLocationService(); |
||
346 | $location = $locationService->loadLocation($this->generateId('location', 1)); |
||
347 | |||
348 | $legacyDateTime = new \DateTime(); |
||
349 | $legacyDateTime->setTimestamp(1030968000); |
||
350 | |||
351 | // $location |
||
352 | $this->assertPropertiesCorrect( |
||
353 | array( |
||
354 | 'id' => $this->generateId('location', 1), |
||
355 | 'status' => 1, |
||
356 | 'priority' => 0, |
||
357 | 'hidden' => false, |
||
358 | 'invisible' => false, |
||
359 | 'remoteId' => '629709ba256fe317c3ddcee35453a96a', |
||
360 | 'parentLocationId' => $this->generateId('location', 1), |
||
361 | 'pathString' => '/1/', |
||
362 | 'depth' => 0, |
||
363 | 'sortField' => 1, |
||
364 | 'sortOrder' => 1, |
||
365 | ), |
||
366 | $location |
||
367 | ); |
||
368 | |||
369 | // $location->contentInfo |
||
370 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', $location->contentInfo); |
||
371 | $this->assertPropertiesCorrect( |
||
372 | array( |
||
373 | 'id' => $this->generateId('content', 0), |
||
374 | 'name' => 'Top Level Nodes', |
||
375 | 'sectionId' => 1, |
||
376 | 'mainLocationId' => 1, |
||
377 | 'contentTypeId' => 1, |
||
378 | 'currentVersionNo' => 1, |
||
379 | 'published' => 1, |
||
380 | 'ownerId' => 14, |
||
381 | 'modificationDate' => $legacyDateTime, |
||
382 | 'publishedDate' => $legacyDateTime, |
||
383 | 'alwaysAvailable' => 1, |
||
384 | 'remoteId' => null, |
||
385 | 'mainLanguageCode' => 'eng-GB', |
||
386 | ), |
||
387 | $location->contentInfo |
||
388 | ); |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Test for the loadLocation() method. |
||
393 | * |
||
394 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
395 | * |
||
396 | * @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
||
397 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
398 | */ |
||
399 | public function testLoadLocationStructValues(Location $location) |
||
400 | { |
||
401 | $this->assertPropertiesCorrect( |
||
402 | array( |
||
403 | 'id' => $this->generateId('location', 5), |
||
404 | 'priority' => 0, |
||
405 | 'hidden' => false, |
||
406 | 'invisible' => false, |
||
407 | 'remoteId' => '3f6d92f8044aed134f32153517850f5a', |
||
408 | 'parentLocationId' => $this->generateId('location', 1), |
||
409 | 'pathString' => '/1/5/', |
||
410 | 'depth' => 1, |
||
411 | 'sortField' => 1, |
||
412 | 'sortOrder' => 1, |
||
413 | ), |
||
414 | $location |
||
415 | ); |
||
416 | |||
417 | $this->assertInstanceOf( |
||
418 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
||
419 | $location->contentInfo |
||
420 | ); |
||
421 | $this->assertEquals($this->generateId('object', 4), $location->contentInfo->id); |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Test for the loadLocation() method. |
||
426 | * |
||
427 | * @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
||
428 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
429 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
430 | */ |
||
431 | public function testLoadLocationThrowsNotFoundException() |
||
432 | { |
||
433 | $repository = $this->getRepository(); |
||
434 | |||
435 | $nonExistentLocationId = $this->generateId('location', 2342); |
||
436 | /* BEGIN: Use Case */ |
||
437 | $locationService = $repository->getLocationService(); |
||
438 | |||
439 | // Throws exception, if Location with $nonExistentLocationId does not |
||
440 | // exist |
||
441 | $location = $locationService->loadLocation($nonExistentLocationId); |
||
442 | /* END: Use Case */ |
||
443 | } |
||
444 | |||
445 | /** |
||
446 | * Test for the loadLocationByRemoteId() method. |
||
447 | * |
||
448 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId() |
||
449 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
450 | */ |
||
451 | public function testLoadLocationByRemoteId() |
||
452 | { |
||
453 | $repository = $this->getRepository(); |
||
454 | |||
455 | /* BEGIN: Use Case */ |
||
456 | $locationService = $repository->getLocationService(); |
||
457 | |||
458 | $location = $locationService->loadLocationByRemoteId( |
||
459 | '3f6d92f8044aed134f32153517850f5a' |
||
460 | ); |
||
461 | /* END: Use Case */ |
||
462 | |||
463 | $this->assertEquals( |
||
464 | $locationService->loadLocation($this->generateId('location', 5)), |
||
465 | $location |
||
466 | ); |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Test for the loadLocationByRemoteId() method. |
||
471 | * |
||
472 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId() |
||
473 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
474 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
475 | */ |
||
476 | public function testLoadLocationByRemoteIdThrowsNotFoundException() |
||
477 | { |
||
478 | $repository = $this->getRepository(); |
||
479 | |||
480 | /* BEGIN: Use Case */ |
||
481 | $locationService = $repository->getLocationService(); |
||
482 | |||
483 | // Throws exception, since Location with remote ID does not exist |
||
484 | $location = $locationService->loadLocationByRemoteId( |
||
485 | 'not-exists' |
||
486 | ); |
||
487 | /* END: Use Case */ |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * Test for the loadLocations() method. |
||
492 | * |
||
493 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
||
494 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
495 | */ |
||
496 | public function testLoadLocations() |
||
497 | { |
||
498 | $repository = $this->getRepository(); |
||
499 | |||
500 | $contentId = $this->generateId('object', 4); |
||
501 | /* BEGIN: Use Case */ |
||
502 | // $contentId contains the ID of an existing content object |
||
503 | $contentService = $repository->getContentService(); |
||
504 | $locationService = $repository->getLocationService(); |
||
505 | |||
506 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
507 | |||
508 | $locations = $locationService->loadLocations($contentInfo); |
||
509 | /* END: Use Case */ |
||
510 | |||
511 | $this->assertInternalType('array', $locations); |
||
512 | |||
513 | return $locations; |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * Test for the loadLocations() method. |
||
518 | * |
||
519 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
||
520 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
||
521 | */ |
||
522 | public function testLoadLocationsContent(array $locations) |
||
523 | { |
||
524 | $repository = $this->getRepository(); |
||
525 | $locationService = $repository->getLocationService(); |
||
526 | |||
527 | $this->assertEquals(1, count($locations)); |
||
528 | foreach ($locations as $loadedLocation) { |
||
529 | $this->assertInstanceOf( |
||
530 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
531 | $loadedLocation |
||
532 | ); |
||
533 | } |
||
534 | |||
535 | usort( |
||
536 | $locations, |
||
537 | function ($a, $b) { |
||
538 | strcmp($a->id, $b->id); |
||
539 | } |
||
540 | ); |
||
541 | |||
542 | $this->assertEquals( |
||
543 | array($this->generateId('location', 5)), |
||
544 | array_map( |
||
545 | function (Location $location) { |
||
546 | return $location->id; |
||
547 | }, |
||
548 | $locations |
||
549 | ) |
||
550 | ); |
||
551 | } |
||
552 | |||
553 | /** |
||
554 | * Test for the loadLocations() method. |
||
555 | * |
||
556 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] |
||
557 | * |
||
558 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations($contentInfo, $rootLocation) |
||
559 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
||
560 | */ |
||
561 | public function testLoadLocationsLimitedSubtree() |
||
562 | { |
||
563 | $repository = $this->getRepository(); |
||
564 | |||
565 | $originalLocationId = $this->generateId('location', 54); |
||
566 | $originalParentLocationId = $this->generateId('location', 48); |
||
567 | $newParentLocationId = $this->generateId('location', 43); |
||
568 | /* BEGIN: Use Case */ |
||
569 | // $originalLocationId is the ID of an existing location |
||
570 | // $originalParentLocationId is the ID of the parent location of |
||
571 | // $originalLocationId |
||
572 | // $newParentLocationId is the ID of an existing location outside the tree |
||
573 | // of $originalLocationId and $originalParentLocationId |
||
574 | $locationService = $repository->getLocationService(); |
||
575 | |||
576 | // Location at "/1/48/54" |
||
577 | $originalLocation = $locationService->loadLocation($originalLocationId); |
||
578 | |||
579 | // Create location under "/1/43/" |
||
580 | $locationCreate = $locationService->newLocationCreateStruct($newParentLocationId); |
||
581 | $locationService->createLocation( |
||
582 | $originalLocation->contentInfo, |
||
583 | $locationCreate |
||
584 | ); |
||
585 | |||
586 | $findRootLocation = $locationService->loadLocation($originalParentLocationId); |
||
587 | |||
588 | // Returns an array with only $originalLocation |
||
589 | $locations = $locationService->loadLocations( |
||
590 | $originalLocation->contentInfo, |
||
591 | $findRootLocation |
||
592 | ); |
||
593 | /* END: Use Case */ |
||
594 | |||
595 | $this->assertInternalType('array', $locations); |
||
596 | |||
597 | return $locations; |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * Test for the loadLocations() method. |
||
602 | * |
||
603 | * @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
||
604 | * |
||
605 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
||
606 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationsLimitedSubtree |
||
607 | */ |
||
608 | public function testLoadLocationsLimitedSubtreeContent(array $locations) |
||
609 | { |
||
610 | $this->assertEquals(1, count($locations)); |
||
611 | |||
612 | $this->assertEquals( |
||
613 | $this->generateId('location', 54), |
||
614 | reset($locations)->id |
||
615 | ); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Test for the loadLocations() method. |
||
620 | * |
||
621 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
||
622 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
||
623 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
624 | */ |
||
625 | public function testLoadLocationsThrowsBadStateException() |
||
626 | { |
||
627 | $repository = $this->getRepository(); |
||
628 | |||
629 | /* BEGIN: Use Case */ |
||
630 | $contentTypeService = $repository->getContentTypeService(); |
||
631 | $contentService = $repository->getContentService(); |
||
632 | $locationService = $repository->getLocationService(); |
||
633 | |||
634 | // Create new content, which is not published |
||
635 | $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
||
636 | $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US'); |
||
637 | $contentCreate->setField('name', 'New Folder'); |
||
638 | $content = $contentService->createContent($contentCreate); |
||
639 | |||
640 | // Throws Exception, since $content has no published version, yet |
||
641 | $locationService->loadLocations( |
||
642 | $content->contentInfo |
||
643 | ); |
||
644 | /* END: Use Case */ |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * Test for the loadLocations() method. |
||
649 | * |
||
650 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations($contentInfo, $rootLocation) |
||
651 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
||
652 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
653 | */ |
||
654 | public function testLoadLocationsThrowsBadStateExceptionLimitedSubtree() |
||
655 | { |
||
656 | $repository = $this->getRepository(); |
||
657 | |||
658 | $someLocationId = $this->generateId('location', 2); |
||
659 | /* BEGIN: Use Case */ |
||
660 | // $someLocationId is the ID of an existing location |
||
661 | $contentTypeService = $repository->getContentTypeService(); |
||
662 | $contentService = $repository->getContentService(); |
||
663 | $locationService = $repository->getLocationService(); |
||
664 | |||
665 | // Create new content, which is not published |
||
666 | $folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
||
667 | $contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US'); |
||
668 | $contentCreate->setField('name', 'New Folder'); |
||
669 | $content = $contentService->createContent($contentCreate); |
||
670 | |||
671 | $findRootLocation = $locationService->loadLocation($someLocationId); |
||
672 | |||
673 | // Throws Exception, since $content has no published version, yet |
||
674 | $locationService->loadLocations( |
||
675 | $content->contentInfo, |
||
676 | $findRootLocation |
||
677 | ); |
||
678 | /* END: Use Case */ |
||
679 | } |
||
680 | |||
681 | /** |
||
682 | * Test for the loadLocationChildren() method. |
||
683 | * |
||
684 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren() |
||
685 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
686 | */ |
||
687 | View Code Duplication | public function testLoadLocationChildren() |
|
688 | { |
||
689 | $repository = $this->getRepository(); |
||
690 | |||
691 | $locationId = $this->generateId('location', 5); |
||
692 | /* BEGIN: Use Case */ |
||
693 | // $locationId is the ID of an existing location |
||
694 | $locationService = $repository->getLocationService(); |
||
695 | |||
696 | $location = $locationService->loadLocation($locationId); |
||
697 | |||
698 | $childLocations = $locationService->loadLocationChildren($location); |
||
699 | /* END: Use Case */ |
||
700 | |||
701 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childLocations); |
||
702 | $this->assertInternalType('array', $childLocations->locations); |
||
703 | $this->assertInternalType('int', $childLocations->totalCount); |
||
704 | |||
705 | return $childLocations; |
||
706 | } |
||
707 | |||
708 | /** |
||
709 | * Test for the getLocationChildCount() method. |
||
710 | * |
||
711 | * @see \eZ\Publish\API\Repository\LocationService::getLocationChildCount() |
||
712 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
713 | */ |
||
714 | public function testGetLocationChildCount() |
||
715 | { |
||
716 | // $locationId is the ID of an existing location |
||
717 | $locationService = $this->getRepository()->getLocationService(); |
||
718 | |||
719 | $this->assertSame( |
||
720 | 5, |
||
721 | $locationService->getLocationChildCount( |
||
722 | $locationService->loadLocation($this->generateId('location', 5)) |
||
723 | ) |
||
724 | ); |
||
725 | } |
||
726 | |||
727 | /** |
||
728 | * Test for the loadLocationChildren() method. |
||
729 | * |
||
730 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren() |
||
731 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
732 | */ |
||
733 | public function testLoadLocationChildrenData(LocationList $locations) |
||
734 | { |
||
735 | $this->assertEquals(5, count($locations->locations)); |
||
736 | $this->assertEquals(5, $locations->totalCount); |
||
737 | |||
738 | foreach ($locations->locations as $location) { |
||
739 | $this->assertInstanceOf( |
||
740 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
741 | $location |
||
742 | ); |
||
743 | } |
||
744 | |||
745 | $this->assertEquals( |
||
746 | array( |
||
747 | $this->generateId('location', 12), |
||
748 | $this->generateId('location', 13), |
||
749 | $this->generateId('location', 14), |
||
750 | $this->generateId('location', 44), |
||
751 | $this->generateId('location', 61), |
||
752 | ), |
||
753 | array_map( |
||
754 | function (Location $location) { |
||
755 | return $location->id; |
||
756 | }, |
||
757 | $locations->locations |
||
758 | ) |
||
759 | ); |
||
760 | } |
||
761 | |||
762 | /** |
||
763 | * Test for the loadLocationChildren() method. |
||
764 | * |
||
765 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] |
||
766 | * |
||
767 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset) |
||
768 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
769 | */ |
||
770 | View Code Duplication | public function testLoadLocationChildrenWithOffset() |
|
771 | { |
||
772 | $repository = $this->getRepository(); |
||
773 | |||
774 | $locationId = $this->generateId('location', 5); |
||
775 | /* BEGIN: Use Case */ |
||
776 | // $locationId is the ID of an existing location |
||
777 | $locationService = $repository->getLocationService(); |
||
778 | |||
779 | $location = $locationService->loadLocation($locationId); |
||
780 | |||
781 | $childLocations = $locationService->loadLocationChildren($location, 2); |
||
782 | /* END: Use Case */ |
||
783 | |||
784 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childLocations); |
||
785 | $this->assertInternalType('array', $childLocations->locations); |
||
786 | $this->assertInternalType('int', $childLocations->totalCount); |
||
787 | |||
788 | return $childLocations; |
||
789 | } |
||
790 | |||
791 | /** |
||
792 | * Test for the loadLocationChildren() method. |
||
793 | * |
||
794 | * @param \eZ\Publish\API\Repository\Values\Content\LocationList $locations |
||
795 | * |
||
796 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset) |
||
797 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildrenWithOffset |
||
798 | */ |
||
799 | View Code Duplication | public function testLoadLocationChildrenDataWithOffset(LocationList $locations) |
|
800 | { |
||
801 | $this->assertEquals(3, count($locations->locations)); |
||
802 | $this->assertEquals(5, $locations->totalCount); |
||
803 | |||
804 | foreach ($locations->locations as $location) { |
||
805 | $this->assertInstanceOf( |
||
806 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
807 | $location |
||
808 | ); |
||
809 | } |
||
810 | |||
811 | $this->assertEquals( |
||
812 | array( |
||
813 | $this->generateId('location', 14), |
||
814 | $this->generateId('location', 44), |
||
815 | $this->generateId('location', 61), |
||
816 | ), |
||
817 | array_map( |
||
818 | function (Location $location) { |
||
819 | return $location->id; |
||
820 | }, |
||
821 | $locations->locations |
||
822 | ) |
||
823 | ); |
||
824 | } |
||
825 | |||
826 | /** |
||
827 | * Test for the loadLocationChildren() method. |
||
828 | * |
||
829 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] |
||
830 | * |
||
831 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset, $limit) |
||
832 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
833 | */ |
||
834 | View Code Duplication | public function testLoadLocationChildrenWithOffsetAndLimit() |
|
835 | { |
||
836 | $repository = $this->getRepository(); |
||
837 | |||
838 | $locationId = $this->generateId('location', 5); |
||
839 | /* BEGIN: Use Case */ |
||
840 | // $locationId is the ID of an existing location |
||
841 | $locationService = $repository->getLocationService(); |
||
842 | |||
843 | $location = $locationService->loadLocation($locationId); |
||
844 | |||
845 | $childLocations = $locationService->loadLocationChildren($location, 2, 2); |
||
846 | /* END: Use Case */ |
||
847 | |||
848 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childLocations); |
||
849 | $this->assertInternalType('array', $childLocations->locations); |
||
850 | $this->assertInternalType('int', $childLocations->totalCount); |
||
851 | |||
852 | return $childLocations; |
||
853 | } |
||
854 | |||
855 | /** |
||
856 | * Test for the loadLocationChildren() method. |
||
857 | * |
||
858 | * @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
||
859 | * |
||
860 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset, $limit) |
||
861 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildrenWithOffsetAndLimit |
||
862 | */ |
||
863 | View Code Duplication | public function testLoadLocationChildrenDataWithOffsetAndLimit(LocationList $locations) |
|
864 | { |
||
865 | $this->assertEquals(2, count($locations->locations)); |
||
866 | $this->assertEquals(5, $locations->totalCount); |
||
867 | |||
868 | foreach ($locations->locations as $location) { |
||
869 | $this->assertInstanceOf( |
||
870 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
871 | $location |
||
872 | ); |
||
873 | } |
||
874 | |||
875 | $this->assertEquals( |
||
876 | array( |
||
877 | $this->generateId('location', 14), |
||
878 | $this->generateId('location', 44), |
||
879 | ), |
||
880 | array_map( |
||
881 | function (Location $location) { |
||
882 | return $location->id; |
||
883 | }, |
||
884 | $locations->locations |
||
885 | ) |
||
886 | ); |
||
887 | } |
||
888 | |||
889 | /** |
||
890 | * Test for the newLocationUpdateStruct() method. |
||
891 | * |
||
892 | * @see \eZ\Publish\API\Repository\LocationService::newLocationUpdateStruct() |
||
893 | */ |
||
894 | public function testNewLocationUpdateStruct() |
||
895 | { |
||
896 | $repository = $this->getRepository(); |
||
897 | |||
898 | /* BEGIN: Use Case */ |
||
899 | $locationService = $repository->getLocationService(); |
||
900 | |||
901 | $updateStruct = $locationService->newLocationUpdateStruct(); |
||
902 | /* END: Use Case */ |
||
903 | |||
904 | $this->assertInstanceOf( |
||
905 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationUpdateStruct', |
||
906 | $updateStruct |
||
907 | ); |
||
908 | } |
||
909 | |||
910 | /** |
||
911 | * Test for the updateLocation() method. |
||
912 | * |
||
913 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
914 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
915 | */ |
||
916 | public function testUpdateLocation() |
||
917 | { |
||
918 | $repository = $this->getRepository(); |
||
919 | |||
920 | $originalLocationId = $this->generateId('location', 5); |
||
921 | /* BEGIN: Use Case */ |
||
922 | // $originalLocationId is the ID of an existing location |
||
923 | $locationService = $repository->getLocationService(); |
||
924 | |||
925 | $originalLocation = $locationService->loadLocation($originalLocationId); |
||
926 | |||
927 | $updateStruct = $locationService->newLocationUpdateStruct(); |
||
928 | $updateStruct->priority = 3; |
||
929 | $updateStruct->remoteId = 'c7adcbf1e96bc29bca28c2d809d0c7ef69272651'; |
||
930 | $updateStruct->sortField = Location::SORT_FIELD_PRIORITY; |
||
931 | $updateStruct->sortOrder = Location::SORT_ORDER_DESC; |
||
932 | |||
933 | $updatedLocation = $locationService->updateLocation($originalLocation, $updateStruct); |
||
934 | /* END: Use Case */ |
||
935 | |||
936 | $this->assertInstanceOf( |
||
937 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
||
938 | $updatedLocation |
||
939 | ); |
||
940 | |||
941 | return array( |
||
942 | 'originalLocation' => $originalLocation, |
||
943 | 'updateStruct' => $updateStruct, |
||
944 | 'updatedLocation' => $updatedLocation, |
||
945 | ); |
||
946 | } |
||
947 | |||
948 | /** |
||
949 | * Test for the updateLocation() method. |
||
950 | * |
||
951 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
952 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation |
||
953 | */ |
||
954 | public function testUpdateLocationStructValues(array $data) |
||
955 | { |
||
956 | $originalLocation = $data['originalLocation']; |
||
957 | $updateStruct = $data['updateStruct']; |
||
958 | $updatedLocation = $data['updatedLocation']; |
||
959 | |||
960 | $this->assertPropertiesCorrect( |
||
961 | array( |
||
962 | 'id' => $originalLocation->id, |
||
963 | 'priority' => $updateStruct->priority, |
||
964 | 'hidden' => $originalLocation->hidden, |
||
965 | 'invisible' => $originalLocation->invisible, |
||
966 | 'remoteId' => $updateStruct->remoteId, |
||
967 | 'contentInfo' => $originalLocation->contentInfo, |
||
968 | 'parentLocationId' => $originalLocation->parentLocationId, |
||
969 | 'pathString' => $originalLocation->pathString, |
||
970 | 'depth' => $originalLocation->depth, |
||
971 | 'sortField' => $updateStruct->sortField, |
||
972 | 'sortOrder' => $updateStruct->sortOrder, |
||
973 | ), |
||
974 | $updatedLocation |
||
975 | ); |
||
976 | } |
||
977 | |||
978 | /** |
||
979 | * Test for the updateLocation() method. |
||
980 | * |
||
981 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
982 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
983 | */ |
||
984 | public function testUpdateLocationWithSameRemoteId() |
||
1012 | |||
1013 | /** |
||
1014 | * Test for the updateLocation() method. |
||
1015 | * |
||
1016 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
1017 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1018 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1019 | */ |
||
1020 | public function testUpdateLocationThrowsInvalidArgumentException() |
||
1040 | |||
1041 | /** |
||
1042 | * Test for the updateLocation() method. |
||
1043 | * Ref EZP-23302: Update Location fails if no change is performed with the update. |
||
1044 | * |
||
1045 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
1046 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1047 | */ |
||
1048 | public function testUpdateLocationTwice() |
||
1049 | { |
||
1050 | $repository = $this->getRepository(); |
||
1051 | |||
1052 | $locationId = $this->generateId('location', 5); |
||
1053 | /* BEGIN: Use Case */ |
||
1054 | $locationService = $repository->getLocationService(); |
||
1055 | $repository->setCurrentUser($repository->getUserService()->loadUser(14)); |
||
1056 | |||
1057 | $originalLocation = $locationService->loadLocation($locationId); |
||
1058 | |||
1059 | $updateStruct = $locationService->newLocationUpdateStruct(); |
||
1060 | $updateStruct->priority = 42; |
||
1061 | |||
1062 | $updatedLocation = $locationService->updateLocation($originalLocation, $updateStruct); |
||
1063 | |||
1064 | // Repeated update with the same, unchanged struct |
||
1065 | $secondUpdatedLocation = $locationService->updateLocation($updatedLocation, $updateStruct); |
||
1066 | /* END: Use Case */ |
||
1067 | |||
1068 | $this->assertEquals($updatedLocation->priority, 42); |
||
1069 | $this->assertEquals($secondUpdatedLocation->priority, 42); |
||
1070 | } |
||
1071 | |||
1072 | /** |
||
1073 | * Test for the swapLocation() method. |
||
1074 | * |
||
1075 | * @see \eZ\Publish\API\Repository\LocationService::swapLocation() |
||
1076 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1077 | */ |
||
1078 | public function testSwapLocation() |
||
1115 | |||
1116 | /** |
||
1117 | * Test for the hideLocation() method. |
||
1118 | * |
||
1119 | * @see \eZ\Publish\API\Repository\LocationService::hideLocation() |
||
1120 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1121 | */ |
||
1122 | public function testHideLocation() |
||
1158 | |||
1159 | /** |
||
1160 | * Assert that $expectedValues are set in the subtree starting at $location. |
||
1161 | * |
||
1162 | * @param array $expectedValues |
||
1163 | * @param Location $location |
||
1164 | */ |
||
1165 | protected function assertSubtreeProperties(array $expectedValues, Location $location, $stopId = null) |
||
1185 | |||
1186 | /** |
||
1187 | * Test for the unhideLocation() method. |
||
1188 | * |
||
1189 | * @see \eZ\Publish\API\Repository\LocationService::unhideLocation() |
||
1190 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testHideLocation |
||
1191 | */ |
||
1192 | public function testUnhideLocation() |
||
1229 | |||
1230 | /** |
||
1231 | * Test for the unhideLocation() method. |
||
1232 | * |
||
1233 | * @see \eZ\Publish\API\Repository\LocationService::unhideLocation() |
||
1234 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation |
||
1235 | */ |
||
1236 | public function testUnhideLocationNotUnhidesHiddenSubtree() |
||
1294 | |||
1295 | /** |
||
1296 | * Test for the deleteLocation() method. |
||
1297 | * |
||
1298 | * @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
||
1299 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1300 | */ |
||
1301 | public function testDeleteLocation() |
||
1343 | |||
1344 | /** |
||
1345 | * Test for the deleteLocation() method. |
||
1346 | * |
||
1347 | * @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
||
1348 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation |
||
1349 | */ |
||
1350 | public function testDeleteLocationDecrementsChildCountOnParent() |
||
1388 | |||
1389 | /** |
||
1390 | * Test for the deleteLocation() method. |
||
1391 | * |
||
1392 | * Related issue: EZP-21904 |
||
1393 | * |
||
1394 | * @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
||
1395 | * @expectedException eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1396 | */ |
||
1397 | public function testDeleteContentObjectLastLocation() |
||
1433 | |||
1434 | /** |
||
1435 | * Test for the copySubtree() method. |
||
1436 | * |
||
1437 | * @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
||
1438 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1439 | */ |
||
1440 | public function testCopySubtree() |
||
1485 | |||
1486 | /** |
||
1487 | * Asserts that given Content has default ContentStates. |
||
1488 | * |
||
1489 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
1490 | */ |
||
1491 | View Code Duplication | private function assertDefaultContentStates(ContentInfo $contentInfo) |
|
1510 | |||
1511 | /** |
||
1512 | * Test for the copySubtree() method. |
||
1513 | * |
||
1514 | * @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
||
1515 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
||
1516 | */ |
||
1517 | public function testCopySubtreeUpdatesSubtreeProperties() |
||
1576 | |||
1577 | /** |
||
1578 | * Test for the copySubtree() method. |
||
1579 | * |
||
1580 | * @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
||
1581 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
||
1582 | */ |
||
1583 | public function testCopySubtreeIncrementsChildCountOfNewParent() |
||
1621 | |||
1622 | /** |
||
1623 | * Test for the copySubtree() method. |
||
1624 | * |
||
1625 | * @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
||
1626 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1627 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
||
1628 | */ |
||
1629 | public function testCopySubtreeThrowsInvalidArgumentException() |
||
1656 | |||
1657 | /** |
||
1658 | * Test for the moveSubtree() method. |
||
1659 | * |
||
1660 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1661 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
1662 | */ |
||
1663 | public function testMoveSubtree() |
||
1706 | |||
1707 | /** |
||
1708 | * Test for the moveSubtree() method. |
||
1709 | * |
||
1710 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1711 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
1712 | */ |
||
1713 | public function testMoveSubtreeHidden() |
||
1759 | |||
1760 | /** |
||
1761 | * Test for the moveSubtree() method. |
||
1762 | * |
||
1763 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1764 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
1765 | */ |
||
1766 | public function testMoveSubtreeUpdatesSubtreeProperties() |
||
1820 | |||
1821 | /** |
||
1822 | * Test for the moveSubtree() method. |
||
1823 | * |
||
1824 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1825 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtreeUpdatesSubtreeProperties |
||
1826 | */ |
||
1827 | public function testMoveSubtreeUpdatesSubtreePropertiesHidden() |
||
1885 | |||
1886 | /** |
||
1887 | * Test for the moveSubtree() method. |
||
1888 | * |
||
1889 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1890 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
1891 | */ |
||
1892 | View Code Duplication | public function testMoveSubtreeIncrementsChildCountOfNewParent() |
|
1943 | |||
1944 | /** |
||
1945 | * Test for the moveSubtree() method. |
||
1946 | * |
||
1947 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
1948 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
1949 | */ |
||
1950 | View Code Duplication | public function testMoveSubtreeDecrementsChildCountOfOldParent() |
|
2001 | |||
2002 | /** |
||
2003 | * Test for the moveSubtree() method. |
||
2004 | * |
||
2005 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
2006 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
2007 | */ |
||
2008 | public function testMoveSubtreeThrowsInvalidArgumentException() |
||
2037 | |||
2038 | /** |
||
2039 | * Loads properties from all locations in the $location's subtree. |
||
2040 | * |
||
2041 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
2042 | * @param array $properties |
||
2043 | * |
||
2044 | * @return array |
||
2045 | */ |
||
2046 | private function loadSubtreeProperties(Location $location, array $properties = array()) |
||
2058 | |||
2059 | /** |
||
2060 | * Loads assertable properties from the given location. |
||
2061 | * |
||
2062 | * @param \eZ\Publish\API\Repository\Values\Content\Location $location |
||
2063 | * @param mixed[] $overwrite |
||
2064 | * |
||
2065 | * @return array |
||
2066 | */ |
||
2067 | private function loadLocationProperties(Location $location, array $overwrite = array()) |
||
2085 | } |
||
2086 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.