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:
1 | <?php |
||
23 | class LocationServiceAuthorizationTest extends BaseTest |
||
24 | { |
||
25 | /** |
||
26 | * Test for the createLocation() method. |
||
27 | * |
||
28 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
29 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
30 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
31 | */ |
||
32 | View Code Duplication | public function testCreateLocationThrowsUnauthorizedException() |
|
33 | { |
||
34 | $repository = $this->getRepository(); |
||
35 | |||
36 | $editorsGroupId = $this->generateId('group', 13); |
||
37 | |||
38 | /* BEGIN: Use Case */ |
||
39 | $contentService = $repository->getContentService(); |
||
40 | $locationService = $repository->getLocationService(); |
||
41 | |||
42 | $user = $this->createUserVersion1(); |
||
43 | |||
44 | // ContentInfo for "Editors" user group |
||
45 | $contentInfo = $contentService->loadContentInfo($editorsGroupId); |
||
46 | |||
47 | // Set current user to newly created user |
||
48 | $repository->setCurrentUser($user); |
||
|
|||
49 | |||
50 | $locationCreate = $locationService->newLocationCreateStruct(1); |
||
51 | $locationCreate->priority = 23; |
||
52 | $locationCreate->hidden = true; |
||
53 | $locationCreate->remoteId = 'sindelfingen'; |
||
54 | $locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
55 | $locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
56 | |||
57 | // This call will fail with an "UnauthorizedException" |
||
58 | $locationService->createLocation( |
||
59 | $contentInfo, |
||
60 | $locationCreate |
||
61 | ); |
||
62 | /* END: Use Case */ |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Test for the createLocation() method. Tests a case when user doesn't have content/manage_locations policy for the new location ID. |
||
67 | * |
||
68 | * @see \eZ\Publish\API\Repository\LocationService::createLocation() |
||
69 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
70 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
71 | */ |
||
72 | public function testCreateLocationThrowsUnauthorizedExceptionDueToLackOfContentManageLocationsPolicy() |
||
122 | |||
123 | /** |
||
124 | * Test for the loadLocation() method. |
||
125 | * |
||
126 | * @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
||
127 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
128 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
129 | */ |
||
130 | View Code Duplication | public function testLoadLocationThrowsUnauthorizedException() |
|
131 | { |
||
132 | $repository = $this->getRepository(); |
||
133 | |||
134 | $editorsGroupId = $this->generateId('group', 13); |
||
135 | |||
136 | /* BEGIN: Use Case */ |
||
137 | $locationService = $repository->getLocationService(); |
||
138 | |||
139 | $user = $this->createUserVersion1(); |
||
140 | |||
141 | // Set current user to newly created user |
||
142 | $repository->setCurrentUser($user); |
||
143 | |||
144 | // This call will fail with an "UnauthorizedException" |
||
145 | $locationService->loadLocation($editorsGroupId); |
||
146 | /* END: Use Case */ |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Test for the loadLocationByRemoteId() method. |
||
151 | * |
||
152 | * @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId() |
||
153 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
154 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId |
||
155 | */ |
||
156 | public function testLoadLocationByRemoteIdThrowsUnauthorizedException() |
||
175 | |||
176 | /** |
||
177 | * Test for the loadLocations() method. |
||
178 | * |
||
179 | * @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
||
180 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
||
181 | */ |
||
182 | public function testLoadLocationsNoAccess() |
||
204 | |||
205 | /** |
||
206 | * Test for the updateLocation() method. |
||
207 | * |
||
208 | * @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
||
209 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
210 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation |
||
211 | */ |
||
212 | public function testUpdateLocationThrowsUnauthorizedException() |
||
241 | |||
242 | /** |
||
243 | * Test for the swapLocation() method. |
||
244 | * |
||
245 | * @see \eZ\Publish\API\Repository\LocationService::swapLocation() |
||
246 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
247 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testSwapLocation |
||
248 | */ |
||
249 | public function testSwapLocationThrowsUnauthorizedException() |
||
280 | |||
281 | /** |
||
282 | * Test for the hideLocation() method. |
||
283 | * |
||
284 | * @see \eZ\Publish\API\Repository\LocationService::hideLocation() |
||
285 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
286 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testHideLocation |
||
287 | */ |
||
288 | View Code Duplication | public function testHideLocationThrowsUnauthorizedException() |
|
308 | |||
309 | /** |
||
310 | * Test for the unhideLocation() method. |
||
311 | * |
||
312 | * @see \eZ\Publish\API\Repository\LocationService::unhideLocation() |
||
313 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
314 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation |
||
315 | */ |
||
316 | View Code Duplication | public function testUnhideLocationThrowsUnauthorizedException() |
|
317 | { |
||
318 | $repository = $this->getRepository(); |
||
319 | |||
320 | $editorsGroupId = $this->generateId('group', 13); |
||
321 | |||
322 | /* BEGIN: Use Case */ |
||
323 | $user = $this->createUserVersion1(); |
||
324 | |||
325 | $locationService = $repository->getLocationService(); |
||
326 | |||
327 | $visibleLocation = $locationService->loadLocation($editorsGroupId); |
||
328 | |||
329 | // Hide location |
||
330 | $hiddenLocation = $locationService->hideLocation($visibleLocation); |
||
331 | |||
332 | // Set current user to newly created user |
||
333 | $repository->setCurrentUser($user); |
||
334 | |||
335 | // This call will fail with an "UnauthorizedException" |
||
336 | $locationService->unhideLocation($hiddenLocation); |
||
337 | /* END: Use Case */ |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Test for the deleteLocation() method. |
||
342 | * |
||
343 | * @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
||
344 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
345 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation |
||
346 | */ |
||
347 | View Code Duplication | public function testDeleteLocationThrowsUnauthorizedException() |
|
367 | |||
368 | /** |
||
369 | * Test for the deleteLocation() method. |
||
370 | * |
||
371 | * @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
||
372 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
373 | * @expectedExceptionMessage User does not have access to 'remove' 'content' |
||
374 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation |
||
375 | */ |
||
376 | public function testDeleteLocationWithSubtreeThrowsUnauthorizedException() |
||
456 | |||
457 | /** |
||
458 | * Test for the copySubtree() method. |
||
459 | * |
||
460 | * @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
||
461 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
462 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
||
463 | */ |
||
464 | public function testCopySubtreeThrowsUnauthorizedException() |
||
498 | |||
499 | /** |
||
500 | * Test for the moveSubtree() method. |
||
501 | * |
||
502 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
||
503 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
504 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
||
505 | */ |
||
506 | public function testMoveSubtreeThrowsUnauthorizedException() |
||
540 | } |
||
541 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.