Skip to content

Commit

Permalink
Add composer naming tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Richter committed Mar 4, 2024
1 parent 88107aa commit b3eeca0
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Classes/Domain/Model/PublishedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ public function getComposers(): string
return Collection::wrap($this->containedWorks->toArray())->
map( function($work) { return self::getWorkComposerName($work); } )->
unique()->
join(';');
join('; ');
}

protected static function getComposerName(GndPerson $composer): string
Expand Down
141 changes: 141 additions & 0 deletions Tests/Functional/Domain/Model/PublishedItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
namespace Slub\MpdbCore\Tests\Unit\Domain\Model;

use Slub\DmNorm\Domain\Model\GndPerson;
use Slub\DmNorm\Domain\Model\GndWork;
use Slub\MpdbCore\Domain\Model\PublishedItem;
use Slub\MpdbCore\Domain\Model\PublishedSubitem;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Test case.
*
* @author Matthias Richter <matthias.richter@slub-dresden.de>
*/
class PublishedItemTest extends FunctionalTestCase
{
/**
* @var \Slub\PublisherDb\Domain\Model\PublishedItem
*/
protected ?PublishedItem $subject = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndPerson
*/
protected ?GndPerson $composer1 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndPerson
*/
protected ?GndPerson $composer2 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndWork
*/
protected ?GndWork $work1 = null;

/**
* @var \Slub\DmNorm\Domain\Model\GndWork
*/
protected ?GndWork $work2 = null;

/**
* @var string
*/
protected string $nameComposer1 = 'Composer 1';

/**
* @var string
*/
protected string $nameComposer2 = 'Composer 2';

protected function setUp(): void
{
parent::setUp();
$this->subject = new PublishedItem();

$this->composer1 = new GndPerson();
$this->composer2 = new GndPerson();
$this->composer1->setName($this->nameComposer1);
$this->composer2->setName($this->nameComposer2);

$this->work1 = new GndWork();
$this->work2 = new GndWork();
$this->work1->setFirstComposer($this->composer1);
$this->work2->setFirstComposer($this->composer2);
}

protected function tearDown(): void
{
parent::tearDown();
}

/**
* @test
*/
public function publishedItemWithOneComposerReturnsComposer()
{
$this->subject->addFirstComposer($this->composer1);

self::assertSame(
$this->nameComposer1,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithManyComposersReturnsComposers()
{
$this->subject->addFirstComposer($this->composer1);
$this->subject->addFirstComposer($this->composer2);
$namesString = implode('; ', [$this->nameComposer1, $this->nameComposer2]);

self::assertSame(
$namesString,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposersReturnsOneWorkComposer()
{
$this->subject->addContainedWork($this->work1);

self::assertSame(
$this->nameComposer1,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposerReturnsManyWorkComposers()
{
$this->subject->addContainedWork($this->work1);
$this->subject->addContainedWork($this->work2);
$namesString = implode('; ', [$this->nameComposer1, $this->nameComposer2]);

self::assertSame(
$namesString,
$this->subject->getComposers()
);
}

/**
* @test
*/
public function publishedItemWithoutComposerWithoutWorkcomposersReturnsString()
{
self::assertSame(
'',
$this->subject->getComposers()
);
}

}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"ci:php": [ "@ci:php:stan" ],
"ci:php:stan": [ "phpstan analyse Classes" ],
"ci:tests": [ "@ci:tests:unit" ],
"ci:tests:unit": [ "phpunit -c config/UnitTests.xml" ]
"ci:tests:unit": [ "phpunit -c config/UnitTests.xml" ],
"ci:tests:functional": [ "phpunit -c config/FunctionalTests.xml" ]
},
"extra": {
"typo3/cms": {
Expand Down
29 changes: 29 additions & 0 deletions config/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuites>
<testsuite name="MpdbCore">
<directory>../Tests/Functional</directory>
</testsuite>
</testsuites>

<php>
<!--
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests
with TYPO3 core v11 and up.
Will always be done with next major version.
To still suppress warnings, notices and deprecations, do NOT define the constant at all.
-->
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
7 changes: 0 additions & 7 deletions config/UnitTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
colors="true"
failOnRisky="true"
failOnWarning="true"
requireCoverageMetadata="true"
>
<testsuites>
<testsuite name="MpdbCore">
<directory>../Tests/Unit</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>../Classes</directory>
</include>
</source>

<php>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
Expand Down

0 comments on commit b3eeca0

Please sign in to comment.