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 BaseIntegrationTest 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 BaseIntegrationTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
44 | abstract class BaseIntegrationTest extends Tests\BaseTest |
||
45 | { |
||
46 | /** |
||
47 | * Content version archive limit (default). |
||
48 | * Note: currently there is no way to retrieve this setting from the ContentService. |
||
49 | */ |
||
50 | const VERSION_ARCHIVE_LIMIT = 5; |
||
51 | |||
52 | /** |
||
53 | * Identifier of the custom field. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $customFieldIdentifier = 'data'; |
||
58 | |||
59 | /** |
||
60 | * Get name of tested field type. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | abstract public function getTypeName(); |
||
65 | |||
66 | /** |
||
67 | * Get expected settings schema. |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | abstract public function getSettingsSchema(); |
||
72 | |||
73 | /** |
||
74 | * Get a valid $fieldSettings value. |
||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | abstract public function getValidFieldSettings(); |
||
79 | |||
80 | /** |
||
81 | * Get $fieldSettings value not accepted by the field type. |
||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | abstract public function getInvalidFieldSettings(); |
||
86 | |||
87 | /** |
||
88 | * Get expected validator schema. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | abstract public function getValidatorSchema(); |
||
93 | |||
94 | /** |
||
95 | * Get a valid $validatorConfiguration. |
||
96 | * |
||
97 | * @return mixed |
||
98 | */ |
||
99 | abstract public function getValidValidatorConfiguration(); |
||
100 | |||
101 | /** |
||
102 | * Get $validatorConfiguration not accepted by the field type. |
||
103 | * |
||
104 | * @return mixed |
||
105 | */ |
||
106 | abstract public function getInvalidValidatorConfiguration(); |
||
107 | |||
108 | /** |
||
109 | * Get initial field data for valid object creation. |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | abstract public function getValidCreationFieldData(); |
||
114 | |||
115 | /** |
||
116 | * Get name generated by the given field type (via fieldType->getName()). |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | abstract public function getFieldName(); |
||
121 | |||
122 | /** |
||
123 | * Asserts that the field data was loaded correctly. |
||
124 | * |
||
125 | * Asserts that the data provided by {@link getValidCreationFieldData()} |
||
126 | * was stored and loaded correctly. |
||
127 | * |
||
128 | * @param Field $field |
||
129 | */ |
||
130 | abstract public function assertFieldDataLoadedCorrect(Field $field); |
||
131 | |||
132 | /** |
||
133 | * Get field data which will result in errors during creation. |
||
134 | * |
||
135 | * This is a PHPUnit data provider. |
||
136 | * |
||
137 | * The returned records must contain of an error producing data value and |
||
138 | * the expected exception class (from the API or SPI, not implementation |
||
139 | * specific!) as the second element. For example: |
||
140 | * |
||
141 | * <code> |
||
142 | * array( |
||
143 | * array( |
||
144 | * new DoomedValue( true ), |
||
145 | * 'eZ\\Publish\\API\\Repository\\Exceptions\\ContentValidationException' |
||
146 | * ), |
||
147 | * // ... |
||
148 | * ); |
||
149 | * </code> |
||
150 | * |
||
151 | * @return array[] |
||
152 | */ |
||
153 | abstract public function provideInvalidCreationFieldData(); |
||
154 | |||
155 | /** |
||
156 | * Get valid field data for updating content. |
||
157 | * |
||
158 | * @return mixed |
||
159 | */ |
||
160 | abstract public function getValidUpdateFieldData(); |
||
161 | |||
162 | /** |
||
163 | * Asserts the the field data was loaded correctly. |
||
164 | * |
||
165 | * Asserts that the data provided by {@link getValidUpdateFieldData()} |
||
166 | * was stored and loaded correctly. |
||
167 | * |
||
168 | * @param Field $field |
||
169 | */ |
||
170 | abstract public function assertUpdatedFieldDataLoadedCorrect(Field $field); |
||
171 | |||
172 | /** |
||
173 | * Get field data which will result in errors during update. |
||
174 | * |
||
175 | * This is a PHPUnit data provider. |
||
176 | * |
||
177 | * The returned records must contain of an error producing data value and |
||
178 | * the expected exception class (from the API or SPI, not implementation |
||
179 | * specific!) as the second element. For example: |
||
180 | * |
||
181 | * <code> |
||
182 | * array( |
||
183 | * array( |
||
184 | * new DoomedValue( true ), |
||
185 | * 'eZ\\Publish\\API\\Repository\\Exceptions\\ContentValidationException' |
||
186 | * ), |
||
187 | * // ... |
||
188 | * ); |
||
189 | * </code> |
||
190 | * |
||
191 | * @return array[] |
||
192 | */ |
||
193 | abstract public function provideInvalidUpdateFieldData(); |
||
194 | |||
195 | /** |
||
196 | * Asserts the the field data was loaded correctly. |
||
197 | * |
||
198 | * Asserts that the data provided by {@link getValidCreationFieldData()} |
||
199 | * was copied and loaded correctly. |
||
200 | * |
||
201 | * @param Field $field |
||
202 | */ |
||
203 | abstract public function assertCopiedFieldDataLoadedCorrectly(Field $field); |
||
204 | |||
205 | /** |
||
206 | * Get data to test to hash method. |
||
207 | * |
||
208 | * This is a PHPUnit data provider |
||
209 | * |
||
210 | * The returned records must have the the original value assigned to the |
||
211 | * first index and the expected hash result to the second. For example: |
||
212 | * |
||
213 | * <code> |
||
214 | * array( |
||
215 | * array( |
||
216 | * new MyValue( true ), |
||
217 | * array( 'myValue' => true ), |
||
218 | * ), |
||
219 | * // ... |
||
220 | * ); |
||
221 | * </code> |
||
222 | * |
||
223 | * @return array |
||
224 | */ |
||
225 | abstract public function provideToHashData(); |
||
226 | |||
227 | /** |
||
228 | * Get hashes and their respective converted values. |
||
229 | * |
||
230 | * This is a PHPUnit data provider |
||
231 | * |
||
232 | * The returned records must have the the input hash assigned to the |
||
233 | * first index and the expected value result to the second. For example: |
||
234 | * |
||
235 | * <code> |
||
236 | * array( |
||
237 | * array( |
||
238 | * array( 'myValue' => true ), |
||
239 | * new MyValue( true ), |
||
240 | * ), |
||
241 | * // ... |
||
242 | * ); |
||
243 | * </code> |
||
244 | * |
||
245 | * @return array |
||
246 | */ |
||
247 | abstract public function provideFromHashData(); |
||
248 | |||
249 | /** |
||
250 | * Method called after content creation. |
||
251 | * |
||
252 | * Useful, if additional stuff should be executed (like creating the actual |
||
253 | * user). |
||
254 | * |
||
255 | * We cannot just overwrite the testCreateContent method, since this messes |
||
256 | * up PHPUnits @depends sorting of tests, so everything will be skipped. |
||
257 | * |
||
258 | * @param Repository\Repository $repository |
||
259 | * @param Repository\Values\Content\Content $content |
||
260 | */ |
||
261 | public function postCreationHook(Repository\Repository $repository, Repository\Values\Content\Content $content) |
||
262 | { |
||
263 | // Do nothing by default |
||
264 | } |
||
265 | |||
266 | public function getValidContentTypeConfiguration(): array |
||
267 | { |
||
268 | return []; |
||
269 | } |
||
270 | |||
271 | public function getValidFieldConfiguration(): array |
||
272 | { |
||
273 | return []; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentType |
||
278 | */ |
||
279 | public function testCreateContentType() |
||
280 | { |
||
281 | $contentType = $this->createContentType( |
||
282 | $this->getValidFieldSettings(), |
||
283 | $this->getValidValidatorConfiguration(), |
||
284 | $this->getValidContentTypeConfiguration(), |
||
285 | $this->getValidFieldConfiguration() |
||
286 | ); |
||
287 | |||
288 | $this->assertNotNull($contentType->id); |
||
289 | |||
290 | return $contentType; |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * For checking if field type can be used in name/url schema (pattern). |
||
295 | * |
||
296 | * @return bool |
||
297 | */ |
||
298 | protected function checkSupportGetName() |
||
299 | { |
||
300 | return true; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * Creates a content type under test with $fieldSettings and |
||
305 | * $validatorConfiguration. |
||
306 | * |
||
307 | * $typeCreateOverride and $fieldCreateOverride can be used to selectively |
||
308 | * override settings on the type create struct and field create struct. |
||
309 | * |
||
310 | * @param mixed $fieldSettings |
||
311 | * @param mixed $validatorConfiguration |
||
312 | * @param array $typeCreateOverride |
||
313 | * @param array $fieldCreateOverride |
||
314 | * |
||
315 | * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
||
316 | */ |
||
317 | protected function createContentType($fieldSettings, $validatorConfiguration, array $typeCreateOverride = [], array $fieldCreateOverride = []) |
||
318 | { |
||
319 | $repository = $this->getRepository(); |
||
320 | $contentTypeService = $repository->getContentTypeService(); |
||
321 | |||
322 | $contentTypeIdentifier = 'test-' . $this->getTypeName(); |
||
323 | |||
324 | try { |
||
325 | return $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); |
||
326 | } catch (Repository\Exceptions\NotFoundException $e) { |
||
327 | // Move on to creating Content Type |
||
328 | } |
||
329 | |||
330 | $createStruct = $contentTypeService->newContentTypeCreateStruct( |
||
331 | $contentTypeIdentifier |
||
332 | ); |
||
333 | $createStruct->mainLanguageCode = $this->getOverride('mainLanguageCode', $typeCreateOverride, 'eng-GB'); |
||
334 | $createStruct->remoteId = $this->getTypeName(); |
||
335 | $createStruct->names = $this->getOverride('names', $typeCreateOverride, ['eng-GB' => 'Test']); |
||
336 | $createStruct->creatorId = 14; |
||
337 | $createStruct->creationDate = $this->createDateTime(); |
||
338 | |||
339 | if ($this->checkSupportGetName()) { |
||
340 | $createStruct->nameSchema = '<name> <data>'; |
||
341 | $createStruct->urlAliasSchema = '<data>'; |
||
342 | } |
||
343 | |||
344 | $nameFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('name', 'ezstring'); |
||
345 | $nameFieldCreate->names = ['eng-GB' => 'Title']; |
||
346 | $nameFieldCreate->fieldGroup = 'main'; |
||
347 | $nameFieldCreate->position = 1; |
||
348 | $nameFieldCreate->isTranslatable = true; |
||
349 | $createStruct->addFieldDefinition($nameFieldCreate); |
||
350 | |||
351 | $dataFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('data', $this->getTypeName()); |
||
352 | $dataFieldCreate->names = $this->getOverride('names', $fieldCreateOverride, ['eng-GB' => 'Title']); |
||
353 | $dataFieldCreate->fieldGroup = 'main'; |
||
354 | $dataFieldCreate->position = 2; |
||
355 | $dataFieldCreate->isTranslatable = $this->getOverride('isTranslatable', $fieldCreateOverride, false); |
||
356 | |||
357 | // Custom settings |
||
358 | $dataFieldCreate->fieldSettings = $fieldSettings; |
||
359 | $dataFieldCreate->validatorConfiguration = $validatorConfiguration; |
||
360 | |||
361 | $createStruct->addFieldDefinition($dataFieldCreate); |
||
362 | |||
363 | $contentGroup = $contentTypeService->loadContentTypeGroupByIdentifier('Content'); |
||
364 | $contentTypeDraft = $contentTypeService->createContentType($createStruct, [$contentGroup]); |
||
365 | |||
366 | $contentTypeService->publishContentTypeDraft($contentTypeDraft); |
||
367 | $contentType = $contentTypeService->loadContentType($contentTypeDraft->id); |
||
368 | |||
369 | return $contentType; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * Retrieves a value for $key from $overrideValues, falling back to |
||
374 | * $default. |
||
375 | * |
||
376 | * @param string $key |
||
377 | * @param array $overrideValues |
||
378 | * @param mixed $default |
||
379 | * |
||
380 | * @return mixed |
||
381 | */ |
||
382 | protected function getOverride($key, array $overrideValues, $default) |
||
383 | { |
||
384 | return isset($overrideValues[$key]) ? $overrideValues[$key] : $default; |
||
385 | } |
||
386 | |||
387 | /** |
||
388 | * @covers \eZ\Publish\Core\FieldType\FieldType::isEmptyValue |
||
389 | * @dataProvider providerForTestIsEmptyValue |
||
390 | */ |
||
391 | public function testIsEmptyValue($value) |
||
392 | { |
||
393 | $this->assertTrue($this->getRepository()->getFieldTypeService()->getFieldType($this->getTypeName())->isEmptyValue($value)); |
||
394 | } |
||
395 | |||
396 | abstract public function providerForTestIsEmptyValue(); |
||
397 | |||
398 | /** |
||
399 | * @covers \eZ\Publish\Core\FieldType\FieldType::isEmptyValue |
||
400 | * @dataProvider providerForTestIsNotEmptyValue |
||
401 | */ |
||
402 | public function testIsNotEmptyValue($value) |
||
403 | { |
||
404 | $this->assertFalse($this->getRepository()->getFieldTypeService()->getFieldType($this->getTypeName())->isEmptyValue($value)); |
||
405 | } |
||
406 | |||
407 | abstract public function providerForTestIsNotEmptyValue(); |
||
408 | |||
409 | /** |
||
410 | * @depends testCreateContentType |
||
411 | */ |
||
412 | public function testContentTypeField($contentType) |
||
413 | { |
||
414 | $this->assertSame( |
||
415 | $this->getTypeName(), |
||
416 | $contentType->fieldDefinitions[1]->fieldTypeIdentifier |
||
417 | ); |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentType |
||
422 | * @depends testCreateContentType |
||
423 | */ |
||
424 | public function testLoadContentTypeField() |
||
425 | { |
||
426 | $contentType = $this->testCreateContentType(); |
||
427 | |||
428 | $repository = $this->getRepository(); |
||
429 | $contentTypeService = $repository->getContentTypeService(); |
||
430 | |||
431 | return $contentTypeService->loadContentType($contentType->id); |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * @depends testLoadContentTypeField |
||
436 | */ |
||
437 | public function testLoadContentTypeFieldType($contentType) |
||
438 | { |
||
439 | $this->assertSame( |
||
440 | $this->getTypeName(), |
||
441 | $contentType->fieldDefinitions[1]->fieldTypeIdentifier |
||
442 | ); |
||
443 | |||
444 | return $contentType->fieldDefinitions[1]; |
||
445 | } |
||
446 | |||
447 | View Code Duplication | public function testSettingsSchema() |
|
448 | { |
||
449 | $repository = $this->getRepository(); |
||
450 | $fieldTypeService = $repository->getFieldTypeService(); |
||
451 | $fieldType = $fieldTypeService->getFieldType($this->getTypeName()); |
||
452 | |||
453 | $this->assertEquals( |
||
454 | $this->getSettingsSchema(), |
||
455 | $fieldType->getSettingsSchema() |
||
456 | ); |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @depends testLoadContentTypeFieldType |
||
461 | */ |
||
462 | public function testLoadContentTypeFieldData(FieldDefinition $fieldDefinition) |
||
463 | { |
||
464 | $this->assertEquals( |
||
465 | $this->getTypeName(), |
||
466 | $fieldDefinition->fieldTypeIdentifier, |
||
467 | 'Loaded fieldTypeIdentifier does not match.' |
||
468 | ); |
||
469 | $this->assertEquals( |
||
470 | $this->getValidFieldSettings(), |
||
471 | $fieldDefinition->fieldSettings, |
||
472 | 'Loaded fieldSettings do not match.' |
||
473 | ); |
||
474 | $this->assertEquals( |
||
475 | $this->getValidValidatorConfiguration(), |
||
476 | $fieldDefinition->validatorConfiguration, |
||
477 | 'Loaded validatorConfiguration does not match.' |
||
478 | ); |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * @depends testCreateContentType |
||
483 | */ |
||
484 | public function testCreateContentTypeFailsWithInvalidFieldSettings() |
||
485 | { |
||
486 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException::class); |
||
487 | |||
488 | $this->createContentType( |
||
489 | $this->getInvalidFieldSettings(), |
||
490 | $this->getValidValidatorConfiguration() |
||
491 | ); |
||
492 | } |
||
493 | |||
494 | public function testValidatorSchema() |
||
495 | { |
||
496 | $repository = $this->getRepository(); |
||
497 | $fieldTypeService = $repository->getFieldTypeService(); |
||
498 | $fieldType = $fieldTypeService->getFieldType($this->getTypeName()); |
||
499 | |||
500 | $this->assertEquals( |
||
501 | $this->getValidatorSchema(), |
||
502 | $fieldType->getValidatorConfigurationSchema() |
||
503 | ); |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * @depends testCreateContentType |
||
508 | */ |
||
509 | public function testCreateContentTypeFailsWithInvalidValidatorConfiguration() |
||
510 | { |
||
511 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException::class); |
||
512 | |||
513 | $this->createContentType( |
||
514 | $this->getValidFieldSettings(), |
||
515 | $this->getInvalidValidatorConfiguration() |
||
516 | ); |
||
517 | } |
||
518 | |||
519 | /** |
||
520 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent; |
||
521 | * @depends testLoadContentTypeField |
||
522 | */ |
||
523 | public function testCreateContent() |
||
527 | |||
528 | /** |
||
529 | * Creates content with $fieldData. |
||
530 | * |
||
531 | * @param mixed $fieldData |
||
532 | * |
||
533 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
534 | */ |
||
535 | protected function createContent($fieldData, $contentType = null) |
||
556 | |||
557 | /** |
||
558 | * Create multilingual content of given name and FT-specific data. |
||
559 | * |
||
560 | * @param array $names Content names in the form of <code>[languageCode => name]</code> |
||
561 | * @param array $fieldData FT-specific data in the form of <code>[languageCode => data]</code> |
||
562 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
563 | * |
||
564 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
565 | * |
||
566 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
567 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
568 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
569 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
570 | */ |
||
571 | protected function createMultilingualContent(array $names, array $fieldData, array $locationCreateStructs = []) |
||
601 | |||
602 | /** |
||
603 | * @depends testCreateContent |
||
604 | */ |
||
605 | public function testCreatedFieldType($content) |
||
615 | |||
616 | /** |
||
617 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
618 | * @depends testCreateContent |
||
619 | */ |
||
620 | public function testPublishContent() |
||
633 | |||
634 | /** |
||
635 | * @depends testPublishContent |
||
636 | */ |
||
637 | public function testPublishedFieldType($content) |
||
647 | |||
648 | /** |
||
649 | * @depends testPublishContent |
||
650 | */ |
||
651 | public function testPublishedName(Content $content) |
||
658 | |||
659 | /** |
||
660 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
661 | * @depends testCreateContent |
||
662 | */ |
||
663 | View Code Duplication | public function testLoadField() |
|
672 | |||
673 | /** |
||
674 | * @depends testLoadField |
||
675 | */ |
||
676 | public function testLoadFieldType() |
||
688 | |||
689 | /** |
||
690 | * @depends testLoadFieldType |
||
691 | */ |
||
692 | public function testLoadExternalData() |
||
696 | |||
697 | public function testCreateContentWithEmptyFieldValue() |
||
704 | |||
705 | /** |
||
706 | * Test that publishing (and thus indexing) content with an empty field value does not fail. |
||
707 | * |
||
708 | * @depends testCreateContentWithEmptyFieldValue |
||
709 | * |
||
710 | * @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft |
||
711 | */ |
||
712 | public function testPublishContentWithEmptyFieldValue(Content $contentDraft) |
||
718 | |||
719 | /** |
||
720 | * @depends testCreateContentWithEmptyFieldValue |
||
721 | */ |
||
722 | public function testCreatedEmptyFieldValue($content) |
||
732 | |||
733 | /** |
||
734 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
735 | * @depends testCreateContentWithEmptyFieldValue |
||
736 | * @group xx |
||
737 | */ |
||
738 | View Code Duplication | public function testLoadEmptyFieldValue() |
|
747 | |||
748 | /** |
||
749 | * @depends testLoadEmptyFieldValue |
||
750 | */ |
||
751 | public function testLoadEmptyFieldValueType($content) |
||
761 | |||
762 | /** |
||
763 | * @depends testLoadEmptyFieldValueType |
||
764 | */ |
||
765 | public function testLoadEmptyFieldValueData($field) |
||
781 | |||
782 | /** |
||
783 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
784 | * @depends testLoadFieldType |
||
785 | */ |
||
786 | public function testUpdateField() |
||
790 | |||
791 | /** |
||
792 | * Updates the standard published content object with $fieldData. |
||
793 | * |
||
794 | * @param mixed $fieldData |
||
795 | * @param bool $setField If false the update struct will be empty (field value will not be set) |
||
796 | * |
||
797 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
798 | */ |
||
799 | public function updateContent($fieldData, $setField = true) |
||
800 | { |
||
801 | $content = $this->testPublishContent(); |
||
802 | |||
803 | $repository = $this->getRepository(); |
||
804 | $contentService = $repository->getContentService(); |
||
805 | |||
806 | $draft = $contentService->createContentDraft($content->contentInfo); |
||
807 | |||
808 | $updateStruct = $contentService->newContentUpdateStruct(); |
||
809 | if ($setField) { |
||
810 | $updateStruct->setField( |
||
811 | $this->customFieldIdentifier, |
||
812 | $fieldData |
||
813 | ); |
||
814 | } |
||
815 | |||
816 | return $contentService->updateContent($draft->versionInfo, $updateStruct); |
||
817 | } |
||
818 | |||
819 | /** |
||
820 | * @depends testUpdateField |
||
821 | */ |
||
822 | public function testUpdateTypeFieldStillAvailable($content) |
||
832 | |||
833 | /** |
||
834 | * @depends testUpdateTypeFieldStillAvailable |
||
835 | */ |
||
836 | public function testUpdatedDataCorrect(Field $field) |
||
840 | |||
841 | /** |
||
842 | * Tests creeating a new version keeps the existing value. |
||
843 | * |
||
844 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
845 | */ |
||
846 | public function testUpdateFieldNoNewContent() |
||
850 | |||
851 | /** |
||
852 | * @depends testUpdateFieldNoNewContent |
||
853 | */ |
||
854 | public function testUpdateNoNewContentTypeFieldStillAvailable($content) |
||
864 | |||
865 | /** |
||
866 | * @depends testUpdateNoNewContentTypeFieldStillAvailable |
||
867 | */ |
||
868 | public function testUpdatedNoNewContentDataCorrect(Field $field) |
||
872 | |||
873 | /** |
||
874 | * @depends testCreateContent |
||
875 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
876 | */ |
||
877 | public function testCopyField($content) |
||
897 | |||
898 | /** |
||
899 | * @depends testCopyField |
||
900 | */ |
||
901 | public function testCopiedFieldType($content) |
||
911 | |||
912 | /** |
||
913 | * @depends testCopiedFieldType |
||
914 | */ |
||
915 | public function testCopiedExternalData(Field $field) |
||
919 | |||
920 | /** |
||
921 | * @depends testCopyField |
||
922 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::deleteContent |
||
923 | */ |
||
924 | public function testDeleteContent($content) |
||
925 | { |
||
926 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class); |
||
927 | |||
928 | $content = $this->testPublishContent(); |
||
929 | |||
930 | $repository = $this->getRepository(); |
||
931 | $contentService = $repository->getContentService(); |
||
932 | |||
933 | $contentService->deleteContent($content->contentInfo); |
||
934 | |||
935 | $contentService->loadContent($content->contentInfo->id); |
||
936 | } |
||
937 | |||
938 | /** |
||
939 | * Tests failing content creation. |
||
940 | * |
||
941 | * @param mixed $failingValue |
||
942 | * @param string $expectedException |
||
943 | * |
||
944 | * @dataProvider provideInvalidCreationFieldData |
||
945 | * @dep_ends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
||
946 | */ |
||
947 | public function testCreateContentFails($failingValue, $expectedException) |
||
948 | { |
||
949 | try { |
||
950 | $this->createContent($failingValue); |
||
951 | |||
952 | $this->fail('Expected exception not thrown.'); |
||
953 | } catch (PHPUnit_Framework_AssertionFailedError $e) { |
||
954 | throw $e; |
||
955 | } catch (Exception $e) { |
||
956 | $this->assertInstanceOf( |
||
957 | $expectedException, |
||
962 | |||
963 | /** |
||
964 | * Tests failing content update. |
||
965 | * |
||
966 | * @param mixed $failingValue |
||
967 | * @param string $expectedException |
||
968 | * |
||
969 | * @dataProvider provideInvalidUpdateFieldData |
||
970 | */ |
||
971 | public function testUpdateContentFails($failingValue, $expectedException) |
||
976 | |||
977 | protected function removeFieldDefinition() |
||
993 | |||
994 | /** |
||
995 | * Tests removal of field definition from the ContentType of the Content. |
||
996 | */ |
||
997 | public function testRemoveFieldDefinition() |
||
1004 | |||
1005 | protected function addFieldDefinition() |
||
1030 | |||
1031 | /** |
||
1032 | * Tests addition of field definition from the ContentType of the Content. |
||
1033 | */ |
||
1034 | public function testAddFieldDefinition() |
||
1048 | |||
1049 | /** |
||
1050 | * @dataProvider provideToHashData |
||
1051 | */ |
||
1052 | View Code Duplication | public function testToHash($value, $expectedHash) |
|
1063 | |||
1064 | /** |
||
1065 | * @depends testCreateContent |
||
1066 | * @dataProvider provideFromHashData |
||
1067 | * @todo: Requires correct registered FieldTypeService, needs to be |
||
1068 | * maintained! |
||
1069 | */ |
||
1070 | View Code Duplication | public function testFromHash($hash, $expectedValue) |
|
1081 | |||
1082 | /** |
||
1083 | * Test that exceeding default version archive limit has no effect on a published content. |
||
1084 | */ |
||
1085 | public function testExceededVersionArchiveLimitHasNoEffectOnContent() |
||
1106 | |||
1107 | /** |
||
1108 | * Test that deleting new draft does not affect data of published version. |
||
1109 | */ |
||
1110 | public function testDeleteDraftOfPublishedContentDoesNotDeleteData() |
||
1128 | |||
1129 | /** |
||
1130 | * Test creating new translation from existing content with empty field. |
||
1131 | */ |
||
1132 | public function testUpdateContentWithNewTranslationOnEmptyField() |
||
1151 | |||
1152 | /** |
||
1153 | * Get proper multilingual FT-specific Values. It Can be overridden by a Field Type test case. |
||
1154 | * |
||
1155 | * @param string[] $languageCodes List of languages to create data for |
||
1156 | * |
||
1157 | * @return array an array in the form of <code>[languageCode => data]</code> |
||
1158 | */ |
||
1159 | public function getValidMultilingualFieldData(array $languageCodes) |
||
1168 | |||
1169 | /** |
||
1170 | * Test that removing Translation from all Versions works for data from a Field Type. |
||
1171 | * |
||
1172 | * @covers \eZ\Publish\API\Repository\ContentService::deleteTranslation |
||
1173 | */ |
||
1174 | public function testDeleteTranslation() |
||
1243 | } |
||
1244 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.