diff --git a/Classes/Domain/Model/PublishedItem.php b/Classes/Domain/Model/PublishedItem.php index e8e3842..df77fb3 100755 --- a/Classes/Domain/Model/PublishedItem.php +++ b/Classes/Domain/Model/PublishedItem.php @@ -285,7 +285,7 @@ public function setMvdbId(): void $this->mvdbId = $this->publisher->getShorthand() . '_' . $minPlateId; - Collection::wrap($this->publishedSubitems)-> + Collection::wrap($this->publishedSubitems->toArray())-> each( function($subitem) { $this->setSubitemMvdbId($subitem); } ); } @@ -364,7 +364,7 @@ public function setInstrumentation($instrumentation): void * * @return \Slub\MpdbCore\Domain\Model\Publisher $publisher */ - public function getPublisher(): Publisher + public function getPublisher(): ?Publisher { return $this->publisher; } @@ -699,7 +699,7 @@ public function isContainedWorksIdentified(): bool * * @return string $responsiblePerson */ - public function getResponsiblePerson(): GndPerson + public function getResponsiblePerson(): string { return $this->responsiblePerson; } @@ -710,32 +710,11 @@ public function getResponsiblePerson(): GndPerson * @param string $responsiblePerson * @return void */ - public function setResponsiblePerson(GndPerson $responsiblePerson): void + public function setResponsiblePerson(string $responsiblePerson): void { $this->responsiblePerson = $responsiblePerson; } - /** - * Returns the dateOfPublishing - * - * @return \DateTime $dateOfPublishing - */ - public function getDateOfPublishing(): \DateTime - { - return $this->dateOfPublishing; - } - - /** - * Sets the dateOfPublishing - * - * @param \DateTime $dateOfPublishing - * @return void - */ - public function setDateOfPublishing(\DateTime $dateOfPublishing): void - { - $this->dateOfPublishing = $dateOfPublishing; - } - /** * Returns the mvdbId * @@ -820,7 +799,7 @@ public function removeForm(Genre $formToRemove): void * * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Slub\DmOnt\Domain\Model\Genre> form */ - public function getForm(): Genre + public function getGenre(): ObjectStorage { return $this->form; } @@ -831,7 +810,7 @@ public function getForm(): Genre * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Slub\DmOnt\Domain\Model\Genre> $form * @return void */ - public function setForm(ObjectStorage $form): void + public function setGenre(ObjectStorage $form): void { $this->form = $form; } @@ -892,10 +871,10 @@ public function getFinal(): int /** * Sets the final * - * @param bool $final + * @param int $final * @return void */ - public function setFinal(bool $final): void + public function setFinal(int $final): void { $this->final = $final; Collection::wrap($this->getContainedWorks()->toArray())-> @@ -1009,7 +988,7 @@ protected static function getWorkComposerName(GndWork $work): string */ public function getPlateIds(): Collection { - return Collection::wrap($this->publishedSubitems)-> + return Collection::wrap($this->publishedSubitems->toArray())-> map( function($subitem) { return self::getSubitemPlateId($subitem); } ); } diff --git a/Tests/Unit/Domain/Model/PublishedItemTest.php b/Tests/Unit/Domain/Model/PublishedItemTest.php new file mode 100755 index 0000000..154bad6 --- /dev/null +++ b/Tests/Unit/Domain/Model/PublishedItemTest.php @@ -0,0 +1,518 @@ + + */ +class PublishedItemTest extends UnitTestCase +{ + /** + * @var \SLUB\PublisherDb\Domain\Model\PublishedItem + */ + protected $subject = null; + + protected function setUp(): void + { + parent::setUp(); + $this->subject = new PublishedItem(); + } + + protected function tearDown(): void + { + parent::tearDown(); + } + + /** + * @test + */ + public function getTitleReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getTitle() + ); + } + + /** + * @test + */ + public function setTitleForStringSetsTitle() + { + $this->subject->setTitle('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getTitle() + ); + } + + /** + * @test + */ + public function getTypeReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getType() + ); + } + + /** + * @test + */ + public function setTypeForStringSetsType() + { + $this->subject->setType('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getType() + ); + } + + /** + * @test + */ + public function getInstrumentationReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getInstrumentation() + ); + } + + /** + * @test + */ + public function setInstrumentationForStringSetsInstrumentation() + { + $this->subject->setInstrumentation('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getInstrumentation() + ); + } + + /** + * @test + */ + public function getDataAcquisitionCertainReturnsInitialValueForBool() + { + self::assertSame( + false, + $this->subject->getDataAcquisitionCertain() + ); + } + + /** + * @test + */ + public function setDataAcquisitionCertainForBoolSetsDataAcquisitionCertain() + { + $this->subject->setDataAcquisitionCertain(true); + + self::assertSame( + true, + $this->subject->getDataAcquisitionCertain() + ); + } + + /** + * @test + */ + public function getRelatedPersonsKnownReturnsInitialValueForBool() + { + self::assertSame( + false, + $this->subject->getRelatedPersonsKnown() + ); + } + + /** + * @test + */ + public function setRelatedPersonsKnownForBoolSetsRelatedPersonsKnown() + { + $this->subject->setRelatedPersonsKnown(true); + + self::assertSame( + true, + $this->subject->getRelatedPersonsKnown() + ); + } + + /** + * @test + */ + public function getWorkExaminedReturnsInitialValueForBool() + { + self::assertSame( + false, + $this->subject->getWorkExamined() + ); + } + + /** + * @test + */ + public function setWorkExaminedForBoolSetsWorkExamined() + { + $this->subject->setWorkExamined(true); + + self::assertSame( + true, + $this->subject->getWorkExamined() + ); + } + + /** + * @test + */ + public function getDataSetManuallyCheckedReturnsInitialValueForBool() + { + self::assertSame( + false, + $this->subject->getDataSetManuallyChecked() + ); + } + + /** + * @test + */ + public function setDataSetManuallyCheckedForBoolSetsDataSetManuallyChecked() + { + $this->subject->setDataSetManuallyChecked(true); + + self::assertSame( + true, + $this->subject->getDataSetManuallyChecked() + ); + } + + /** + * @test + */ + public function getContainedWorksIdentifiedReturnsInitialValueForBool() + { + self::assertSame( + false, + $this->subject->getContainedWorksIdentified() + ); + } + + /** + * @test + */ + public function setContainedWorksIdentifiedForBoolSetsContainedWorksIdentified() + { + $this->subject->setContainedWorksIdentified(true); + + self::assertSame( + true, + $this->subject->getContainedWorksIdentified() + ); + } + + /** + * @test + */ + public function getResponsiblePersonReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getResponsiblePerson() + ); + } + + /** + * @test + */ + public function setResponsiblePersonForStringSetsResponsiblePerson() + { + $this->subject->setResponsiblePerson('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getResponsiblePerson() + ); + } + + /** + * @test + */ + public function getFinalReturnsInitialValueForInt() + { + self::assertSame( + 0, + $this->subject->getFinal() + ); + } + + /** + * @test + */ + public function setFinalForIntSetsFinal() + { + $this->subject->setFinal(12); + + self::assertSame( + 12, + $this->subject->getFinal() + ); + } + + /** + * @test + */ + public function getLanguageReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getLanguage() + ); + } + + /** + * @test + */ + public function setLanguageForStringSetsLanguage() + { + $this->subject->setLanguage('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getLanguage() + ); + } + + /** + * @test + */ + public function getCommentReturnsInitialValueForString() + { + self::assertSame( + '', + $this->subject->getComment() + ); + } + + /** + * @test + */ + public function setCommentForStringSetsComment() + { + $this->subject->setComment('Conceived at T3CON10'); + + self::assertSame( + 'Conceived at T3CON10', + $this->subject->getComment() + ); + } + + /** + * @test + */ + public function getContainedWorksReturnsInitialValueForWork() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getContainedWorks() + ); + } + + /** + * @test + */ + public function setContainedWorksForObjectStorageContainingWorkSetsContainedWorks() + { + $containedWork = new GndWork(); + $objectStorageHoldingExactlyOneContainedWorks = new ObjectStorage(); + $objectStorageHoldingExactlyOneContainedWorks->attach($containedWork); + $this->subject->setContainedWorks($objectStorageHoldingExactlyOneContainedWorks); + + self::assertSame( + $objectStorageHoldingExactlyOneContainedWorks, + $this->subject->getContainedWorks() + ); + } + + + /** + * @test + */ + public function getEditorsReturnsInitialValueForPerson() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getEditors() + ); + } + + /** + * @test + */ + public function setEditorsForObjectStorageContainingPersonSetsEditors() + { + $editor = new GndPerson(); + $objectStorageHoldingExactlyOneEditors = new ObjectStorage(); + $objectStorageHoldingExactlyOneEditors->attach($editor); + $this->subject->setEditors($objectStorageHoldingExactlyOneEditors); + + self::assertSame( + $objectStorageHoldingExactlyOneEditors, + $this->subject->getEditors() + ); + } + + /** + * @test + */ + public function getInstrumentsReturnsInitialValueForInstrument() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getInstruments() + ); + } + + /** + * @test + */ + public function setInstrumentsForObjectStorageContainingInstrumentSetsInstruments() + { + $instrument = new GndInstrument; + $objectStorageHoldingExactlyOneInstruments = new ObjectStorage(); + $objectStorageHoldingExactlyOneInstruments->attach($instrument); + $this->subject->setInstruments($objectStorageHoldingExactlyOneInstruments); + + self::assertSame( + $objectStorageHoldingExactlyOneInstruments, + $this->subject->getInstruments() + ); + } + + /** + * @test + */ + public function getGenreReturnsInitialValueForGenre() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getGenre() + ); + } + + /** + * @test + */ + public function setGenreForObjectStorageContainingGenreSetsForm() + { + $form = new GndGenre(); + $objectStorageHoldingExactlyOneForm = new ObjectStorage(); + $objectStorageHoldingExactlyOneForm->attach($form); + $this->subject->setGenre($objectStorageHoldingExactlyOneForm); + + self::assertSame( + $objectStorageHoldingExactlyOneForm, + $this->subject->getGenre() + ); + } + + /** + * @test + */ + public function getFirstComposerReturnsInitialValueForPerson() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getFirstComposer() + ); + } + + /** + * @test + */ + public function setFirstComposerForObjectStorageContainingPersonSetsFirstComposer() + { + $firstComposer = new GndPerson(); + $objectStorageHoldingExactlyOneFirstComposer = new ObjectStorage(); + $objectStorageHoldingExactlyOneFirstComposer->attach($firstComposer); + $this->subject->setFirstComposer($objectStorageHoldingExactlyOneFirstComposer); + + self::assertSame( + $objectStorageHoldingExactlyOneFirstComposer, + $this->subject->getFirstComposer() + ); + } + + /** + * @test + */ + public function getPublishedSubitemsReturnsInitialValueForPublishedSubitem() + { + $newObjectStorage = new ObjectStorage(); + self::assertEquals( + $newObjectStorage, + $this->subject->getPublishedSubitems() + ); + } + + /** + * @test + */ + public function setPublishedSubitemsForObjectStorageContainingPublishedSubitemSetsPublishedSubitems() + { + $publishedSubitem = new PublishedSubitem(); + $objectStorageHoldingExactlyOnePublishedSubitems = new ObjectStorage(); + $objectStorageHoldingExactlyOnePublishedSubitems->attach($publishedSubitem); + $this->subject->setPublishedSubitems($objectStorageHoldingExactlyOnePublishedSubitems); + + self::assertSame( + $objectStorageHoldingExactlyOnePublishedSubitems, + $this->subject->getPublishedSubitems() + ); + } + + /** + * @test + */ + public function getPublisherReturnsInitialValueForPublisher() + { + self::assertEquals( + null, + $this->subject->getPublisher() + ); + } + + /** + * @test + */ + public function setPublisherForPublisherSetsPublisher() + { + $publisherFixture = new Publisher(); + $this->subject->setPublisher($publisherFixture); + + self::assertSame( + $publisherFixture, + $this->subject->getPublisher() + ); + } +} diff --git a/composer.json b/composer.json index addaec8..73a53db 100755 --- a/composer.json +++ b/composer.json @@ -44,9 +44,11 @@ "post-autoload-dump": [ "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare" ], - "ci": [ "@ci:php" ], + "ci": [ "@ci:php", "@ci:tests" ], "ci:php": [ "@ci:php:stan" ], - "ci:php:stan": [ "phpstan analyse Classes" ] + "ci:php:stan": [ "phpstan analyse Classes" ], + "ci:tests": [ "@ci:tests:unit" ], + "ci:tests:unit": [ "phpunit -c config/UnitTests.xml" ] }, "extra": { "typo3/cms": { diff --git a/config/UnitTests.xml b/config/UnitTests.xml new file mode 100644 index 0000000..a644f4f --- /dev/null +++ b/config/UnitTests.xml @@ -0,0 +1,29 @@ + + + + + ../Tests/Unit + + + + + + ../Classes + + + + + + + +