-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
624 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Tests/Functional/Content/Infrastructure/Doctrine/ContactFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Tests\Functional\Content\Infrastructure\Doctrine; | ||
|
||
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ContactFactoryInterface; | ||
use Sulu\Bundle\TestBundle\Testing\SuluTestCase; | ||
|
||
class ContactFactoryTest extends SuluTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
self::bootKernel(); | ||
self::purgeDatabase(); | ||
} | ||
|
||
public function createContactFactory(): ContactFactoryInterface | ||
{ | ||
return self::$container->get('sulu_content.contact_factory'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testCreate(?int $contactId): void | ||
{ | ||
$contactFactory = $this->createContactFactory(); | ||
|
||
$result = $contactFactory->create($contactId); | ||
$this->assertSame( | ||
$contactId, | ||
$result ? $result->getId() : $result | ||
); | ||
} | ||
|
||
/** | ||
* @return \Generator<mixed[]> | ||
*/ | ||
public function dataProvider(): \Generator | ||
{ | ||
yield [ | ||
null, | ||
]; | ||
|
||
yield [ | ||
1, | ||
]; | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Application\ContentDataMapper\DataMapper; | ||
|
||
use DateTimeImmutable; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Sulu\Bundle\ContactBundle\Entity\ContactInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentDataMapper\DataMapper\AuthorDataMapper; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ContactFactoryInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
|
||
class AuthorDataMapperTest extends TestCase | ||
{ | ||
protected function createAuthorDataMapperInstance(ContactFactoryInterface $contactFactory): AuthorDataMapper | ||
{ | ||
return new AuthorDataMapper($contactFactory); | ||
} | ||
|
||
public function testMapNoAuthor(): void | ||
{ | ||
$data = [ | ||
'author' => 1, | ||
'authored' => '2020-05-08T00:00:00+00:00', | ||
]; | ||
|
||
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
|
||
$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); | ||
$dimensionContentCollection->getDimensionAttributes() | ||
->shouldBeCalled() | ||
->willReturn(['stage' => 'draft', 'locale' => 'de']); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => null]) | ||
->shouldBeCalled() | ||
->willReturn($unlocalizedDimensionContent); | ||
|
||
$contactFactory = $this->prophesize(ContactFactoryInterface::class); | ||
|
||
$authorMapper = $this->createAuthorDataMapperInstance($contactFactory->reveal()); | ||
$authorMapper->map($data, $dimensionContentCollection->reveal()); | ||
} | ||
|
||
public function testMapLocalizedNoAuthor(): void | ||
{ | ||
$data = [ | ||
'author' => 1, | ||
'authored' => '2020-05-08T00:00:00+00:00', | ||
]; | ||
|
||
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
$unlocalizedDimensionContent->willImplement(AuthorInterface::class); | ||
|
||
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
|
||
$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); | ||
$dimensionContentCollection->getDimensionAttributes() | ||
->shouldBeCalled() | ||
->willReturn(['stage' => 'draft', 'locale' => 'de']); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => null]) | ||
->willReturn($unlocalizedDimensionContent); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => 'de']) | ||
->willReturn($localizedDimensionContent->reveal()); | ||
|
||
$contactFactory = $this->prophesize(ContactFactoryInterface::class); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessage('Expected "$localizedObject" from type "Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface" but "Double\DimensionContentInterface\P3" given.'); | ||
|
||
$authorMapper = $this->createAuthorDataMapperInstance($contactFactory->reveal()); | ||
$authorMapper->map($data, $dimensionContentCollection->reveal()); | ||
} | ||
|
||
public function testMapUnlocalizedAuthor(): void | ||
{ | ||
$data = [ | ||
'author' => 1, | ||
'authored' => '2020-05-08T00:00:00+00:00', | ||
]; | ||
$contact = $this->prophesize(ContactInterface::class); | ||
$contactFactory = $this->prophesize(ContactFactoryInterface::class); | ||
$contactFactory->create(1) | ||
->shouldBeCalled() | ||
->willReturn($contact->reveal()); | ||
|
||
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
$unlocalizedDimensionContent->willImplement(AuthorInterface::class); | ||
|
||
$unlocalizedDimensionContent->setAuthor($contact->reveal()) | ||
->shouldBeCalled(); | ||
$unlocalizedDimensionContent->setAuthored(Argument::that( | ||
function (DateTimeImmutable $date) { | ||
return $date->getTimestamp() === (new \DateTimeImmutable('2020-05-08T00:00:00+00:00'))->getTimestamp(); | ||
}) | ||
)->shouldBeCalled(); | ||
|
||
$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); | ||
$dimensionContentCollection->getDimensionAttributes() | ||
->shouldBeCalled() | ||
->willReturn(['stage' => 'draft', 'locale' => 'de']); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => null]) | ||
->willReturn($unlocalizedDimensionContent->reveal()); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => 'de']) | ||
->willReturn(null); | ||
|
||
$authorMapper = $this->createAuthorDataMapperInstance($contactFactory->reveal()); | ||
$authorMapper->map($data, $dimensionContentCollection->reveal()); | ||
} | ||
|
||
public function testMapLocalizedAuthor(): void | ||
{ | ||
$data = [ | ||
'author' => 1, | ||
'authored' => '2020-05-08T00:00:00+00:00', | ||
]; | ||
$contact = $this->prophesize(ContactInterface::class); | ||
$contactFactory = $this->prophesize(ContactFactoryInterface::class); | ||
$contactFactory->create(1) | ||
->shouldBeCalled() | ||
->willReturn($contact->reveal()); | ||
|
||
$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
$unlocalizedDimensionContent->willImplement(AuthorInterface::class); | ||
|
||
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class); | ||
$localizedDimensionContent->willImplement(AuthorInterface::class); | ||
|
||
$localizedDimensionContent->setAuthor($contact->reveal()) | ||
->shouldBeCalled(); | ||
$localizedDimensionContent->setAuthored(Argument::that( | ||
function (DateTimeImmutable $date) { | ||
return $date->getTimestamp() === (new \DateTimeImmutable('2020-05-08T00:00:00+00:00'))->getTimestamp(); | ||
}) | ||
)->shouldBeCalled(); | ||
|
||
$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class); | ||
$dimensionContentCollection->getDimensionAttributes() | ||
->shouldBeCalled() | ||
->willReturn(['stage' => 'draft', 'locale' => 'de']); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => null]) | ||
->willReturn($unlocalizedDimensionContent->reveal()); | ||
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => 'de']) | ||
->willReturn($localizedDimensionContent->reveal()); | ||
|
||
$authorMapper = $this->createAuthorDataMapperInstance($contactFactory->reveal()); | ||
$authorMapper->map($data, $dimensionContentCollection->reveal()); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
Tests/Unit/Content/Application/ContentMerger/Merger/AuthorMergerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ContentBundle\Tests\Unit\Content\Application\ContentMerger\Merger; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Sulu\Bundle\ContactBundle\Entity\ContactInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\AuthorMerger; | ||
use Sulu\Bundle\ContentBundle\Content\Application\ContentMerger\Merger\MergerInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\AuthorInterface; | ||
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; | ||
|
||
class AuthorMergerTest extends TestCase | ||
{ | ||
protected function getAuthorMergerInstance(): MergerInterface | ||
{ | ||
return new AuthorMerger(); | ||
} | ||
|
||
public function testMergeSourceNotImplementAuthorInterface(): void | ||
{ | ||
$merger = $this->getAuthorMergerInstance(); | ||
|
||
$source = $this->prophesize(DimensionContentInterface::class); | ||
|
||
$target = $this->prophesize(DimensionContentInterface::class); | ||
$target->willImplement(AuthorInterface::class); | ||
$target->setAuthor(Argument::any())->shouldNotBeCalled(); | ||
|
||
$merger->merge($target->reveal(), $source->reveal()); | ||
} | ||
|
||
public function testMergeTargetNotImplementAuthorInterface(): void | ||
{ | ||
$merger = $this->getAuthorMergerInstance(); | ||
|
||
$source = $this->prophesize(DimensionContentInterface::class); | ||
$source->willImplement(AuthorInterface::class); | ||
$source->getAuthor(Argument::any())->shouldNotBeCalled(); | ||
|
||
$target = $this->prophesize(DimensionContentInterface::class); | ||
|
||
$merger->merge($target->reveal(), $source->reveal()); | ||
} | ||
|
||
public function testMergeSet(): void | ||
{ | ||
$merger = $this->getAuthorMergerInstance(); | ||
|
||
$contact = $this->prophesize(ContactInterface::class); | ||
$authoredDate = new \DateTimeImmutable('2020-05-08T00:00:00+00:00'); | ||
|
||
$source = $this->prophesize(DimensionContentInterface::class); | ||
$source->willImplement(AuthorInterface::class); | ||
$source->getAuthor()->willReturn($contact->reveal())->shouldBeCalled(); | ||
$source->getAuthored()->willReturn($authoredDate)->shouldBeCalled(); | ||
|
||
$target = $this->prophesize(DimensionContentInterface::class); | ||
$target->willImplement(AuthorInterface::class); | ||
$target->setAuthor($contact->reveal())->shouldBeCalled(); | ||
$target->setAuthored($authoredDate)->shouldBeCalled(); | ||
|
||
$merger->merge($target->reveal(), $source->reveal()); | ||
} | ||
|
||
public function testMergeNotSet(): void | ||
{ | ||
$merger = $this->getAuthorMergerInstance(); | ||
|
||
$source = $this->prophesize(DimensionContentInterface::class); | ||
$source->willImplement(AuthorInterface::class); | ||
$source->getAuthor()->willReturn(null)->shouldBeCalled(); | ||
$source->getAuthored()->willReturn(null)->shouldBeCalled(); | ||
|
||
$target = $this->prophesize(DimensionContentInterface::class); | ||
$target->willImplement(AuthorInterface::class); | ||
$target->setAuthor(Argument::any())->shouldNotBeCalled(); | ||
$target->setAuthored(Argument::any())->shouldNotBeCalled(); | ||
|
||
$merger->merge($target->reveal(), $source->reveal()); | ||
} | ||
} |
Oops, something went wrong.