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 |
||
| 13 | class ContentTest extends RESTFunctionalTestCase |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Covers POST /content/objects. |
||
| 17 | * |
||
| 18 | * @return string REST content ID |
||
| 19 | */ |
||
| 20 | public function testCreateContent() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @depends testCreateContent |
||
| 65 | * Covers PUBLISH /content/objects/<contentId>/versions/<versionNumber> |
||
| 66 | * |
||
| 67 | * @return string REST content ID |
||
| 68 | */ |
||
| 69 | public function testPublishContent($restContentHref) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @depends testPublishContent |
||
| 81 | * Covers GET /content/objects?remoteId=<remoteId> |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function testRedirectContent($restContentHref) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * @depends testPublishContent |
||
| 95 | */ |
||
| 96 | public function testLoadContent($restContentHref) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @depends testPublishContent |
||
| 108 | */ |
||
| 109 | public function testUpdateContentMetadata($restContentHref) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @depends testPublishContent |
||
| 129 | * |
||
| 130 | * @return string ContentVersion REST ID |
||
| 131 | */ |
||
| 132 | View Code Duplication | public function testCreateDraftFromVersion($restContentHref) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @depends testPublishContent |
||
| 146 | * Covers GET /content/objects/<contentId>/currentversion |
||
| 147 | * @covers \eZ\Publish\Core\REST\Server\Controller\Content::redirectCurrentVersion |
||
| 148 | */ |
||
| 149 | public function testRedirectCurrentVersion($restContentHref) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @depends testCreateDraftFromVersion |
||
| 162 | * Covers GET /content/objects/<contentId>/versions/<versionNumber> |
||
| 163 | * |
||
| 164 | * @param string $restContentVersionHref |
||
| 165 | */ |
||
| 166 | public function testLoadContentVersion($restContentVersionHref) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Covers COPY /content/objects/<contentId>. |
||
| 179 | * @depends testPublishContent |
||
| 180 | * |
||
| 181 | * @return string the copied content href |
||
| 182 | */ |
||
| 183 | public function testCopyContent($restContentHref) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Covers DELETE /content/objects/<versionNumber>. |
||
| 202 | * @depends testCopyContent |
||
| 203 | */ |
||
| 204 | public function testDeleteContent($restContentHref) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @depends testPublishContent |
||
| 216 | * Covers GET /content/objects/<contentId>/versions |
||
| 217 | */ |
||
| 218 | public function testLoadContentVersions($restContentHref) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @depends testPublishContent |
||
| 229 | * |
||
| 230 | * @param string $restContentHref /content/objects/<contentId> |
||
| 231 | * Covers COPY /content/objects/<contentId>/currentversion |
||
| 232 | * |
||
| 233 | * @return string the ID of the created version (/content/objects/<contentId>/versions/<versionNumber> |
||
| 234 | */ |
||
| 235 | View Code Duplication | public function testCreateDraftFromCurrentVersion($restContentHref) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * @depends testCreateDraftFromCurrentVersion |
||
| 249 | * |
||
| 250 | * @param string $restContentVersionHref /api/ezp/v2/content/objects/<contentId>/versions>/<versionNumber> |
||
| 251 | * Covers DELETE /api/ezp/v2/content/objects/<contentId>/versions>/<versionNumber> |
||
| 252 | */ |
||
| 253 | public function testDeleteContentVersion($restContentVersionHref) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @depends testCreateDraftFromVersion |
||
| 264 | * Covers PATCH /content/objects/<contentId>/versions>/<versionNumber> |
||
| 265 | * |
||
| 266 | * @param string $restContentVersionHref /content/objects/<contentId>/versions>/<versionNumber> |
||
| 267 | */ |
||
| 268 | View Code Duplication | public function testUpdateVersion($restContentVersionHref) |
|
| 269 | { |
||
| 270 | $xml = <<< XML |
||
| 271 | <VersionUpdate> |
||
| 272 | <fields> |
||
| 273 | <field> |
||
| 274 | <fieldDefinitionIdentifier>name</fieldDefinitionIdentifier> |
||
| 275 | <languageCode>eng-GB</languageCode> |
||
| 276 | <fieldValue>testUpdateVersion</fieldValue> |
||
| 277 | </field> |
||
| 278 | </fields> |
||
| 279 | </VersionUpdate> |
||
| 280 | XML; |
||
| 281 | |||
| 282 | $request = $this->createHttpRequest('PATCH', $restContentVersionHref, 'VersionUpdate+xml', 'Version+json'); |
||
| 283 | $request->setContent($xml); |
||
| 284 | $response = $this->sendHttpRequest( |
||
| 285 | $request |
||
| 286 | ); |
||
| 287 | |||
| 288 | self::assertHttpResponseCodeEquals($response, 200); |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @depends testPublishContent |
||
| 293 | * Covers GET /content/objects/<contentId>/relations |
||
| 294 | */ |
||
| 295 | public function testRedirectCurrentVersionRelations($restContentHref) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @depends testCreateDraftFromVersion |
||
| 311 | * Covers GET /content/objects/<contentId>/versions/<versionNumber>/relations |
||
| 312 | */ |
||
| 313 | public function testLoadVersionRelations($restContentVersionHref) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @depends testCreateDraftFromVersion |
||
| 324 | * Covers POST /content/objects/<contentId>/versions/<versionNumber>/relations/<relationId> |
||
| 325 | * |
||
| 326 | * @return string created relation HREF (/content/objects/<contentId>/versions/<versionNumber>/relations/<relationId> |
||
| 327 | */ |
||
| 328 | public function testCreateRelation($restContentVersionHref) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @depends testCreateRelation |
||
| 351 | * Covers GET /content/objects/<contentId>/versions/<versionNo>/relations/<relationId> |
||
| 352 | */ |
||
| 353 | public function testLoadVersionRelation($restContentRelationHref) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Returns the Content key from the decoded JSON of $restContentId's contentInfo. |
||
| 366 | * |
||
| 367 | * |
||
| 368 | * @throws \InvalidArgumentException |
||
| 369 | * |
||
| 370 | * @param string $restContentHref /api/ezp/v2/content/objects/<contentId> |
||
| 371 | * |
||
| 372 | * @return array |
||
| 373 | */ |
||
| 374 | private function loadContent($restContentHref) |
||
| 391 | |||
| 392 | public function testCreateView() |
||
| 417 | } |
||
| 418 |