infinito/application/symfony/tests/Unit/Domain/Request/Right/RequestedRightTest.php

122 lines
4.8 KiB
PHP
Raw Normal View History

2019-01-13 21:52:09 +01:00
<?php
namespace tests\Unit\Domain\Request\Right;
2019-01-13 21:52:09 +01:00
2020-04-02 21:13:35 +02:00
use Infinito\DBAL\Types\ActionType;
use Infinito\DBAL\Types\Meta\Right\LayerType;
2020-04-02 21:13:35 +02:00
use Infinito\Domain\Fixture\FixtureSource\ImpressumFixtureSource;
use Infinito\Domain\Repository\LayerRepositoryFactoryService;
use Infinito\Domain\Repository\LayerRepositoryFactoryServiceInterface;
use Infinito\Domain\Request\Entity\RequestedEntity;
use Infinito\Domain\Request\Entity\RequestedEntityInterface;
2020-04-02 21:13:35 +02:00
use Infinito\Domain\Request\Right\RequestedRight;
use Infinito\Domain\Request\Right\RequestedRightInterface;
use Infinito\Entity\Meta\Law;
2020-04-02 21:13:35 +02:00
use Infinito\Entity\Source\PureSource;
use Infinito\Entity\Source\SourceInterface;
2019-04-15 01:37:17 +02:00
use Infinito\Exception\Collection\ContainsElementException;
2020-04-02 21:13:35 +02:00
use Infinito\Exception\Core\NoIdentityCoreException;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2019-01-13 21:52:09 +01:00
/**
* @author kevinfrantz
*/
class RequestedRightTest extends KernelTestCase
{
/**
* @var RequestedRightInterface
*/
private $requestedRight;
2019-01-26 19:39:36 +01:00
/**
* @var LayerRepositoryFactoryServiceInterface
*/
private $layerRepositoryFactoryService;
2019-01-13 21:52:09 +01:00
public function setUp(): void
{
self::bootKernel();
$entityManager = self::$container->get('doctrine.orm.default_entity_manager');
2019-01-26 19:39:36 +01:00
$this->layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager);
$this->requestedRight = new RequestedRight();
2019-01-13 21:52:09 +01:00
}
public function testLayer(): void
{
$layer = LayerType::SOURCE;
$this->assertNull($this->requestedRight->setLayer($layer));
$this->assertEquals($layer, $this->requestedRight->getLayer());
}
public function testLayerException(): void
{
$this->expectException(\TypeError::class);
$this->requestedRight->getLayer();
2019-01-13 21:52:09 +01:00
}
public function testRequestedEntityWithoutAttributes(): void
2019-01-13 21:52:09 +01:00
{
$requestedSource = $this->createMock(RequestedEntity::class);
$this->requestedRight->setRequestedEntity($requestedSource);
2019-04-15 01:37:17 +02:00
$this->expectException(NoIdentityCoreException::class);
2019-01-14 21:27:06 +01:00
$this->requestedRight->getSource();
2019-01-13 21:52:09 +01:00
}
public function testKnownSource(): void
{
2019-01-26 19:39:36 +01:00
$requestedEntity = new RequestedEntity($this->layerRepositoryFactoryService);
2019-03-29 23:21:52 +01:00
$requestedEntity->setSlug(ImpressumFixtureSource::getSlug());
2019-01-26 19:39:36 +01:00
$this->requestedRight->setRequestedEntity($requestedEntity);
$this->requestedRight->setLayer(LayerType::SOURCE);
2019-01-13 21:52:09 +01:00
$sourceResponse1 = $this->requestedRight->getSource();
$this->assertGreaterThan(0, $sourceResponse1->getId());
2019-01-26 19:39:36 +01:00
$requestedEntity->setSlug('');
$this->expectException(NotFoundHttpException::class);
2019-01-14 21:27:06 +01:00
$this->requestedRight->getSource();
}
public function testEqualsSlug(): void
{
2019-03-29 23:21:52 +01:00
$slug = ImpressumFixtureSource::getSlug();
2019-01-26 19:39:36 +01:00
$requestedEntityEntity = new PureSource();
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('getSlug')->willReturn($slug);
$requestedEntity->method('hasSlug')->willReturn(true);
2019-04-15 01:37:17 +02:00
$requestedEntity->method('hasIdentity')->willReturn(true);
2019-01-26 19:39:36 +01:00
$requestedEntity->method('getEntity')->willReturn($requestedEntityEntity);
$this->assertEquals($slug, $requestedEntity->getSlug());
$this->requestedRight->setRequestedEntity($requestedEntity);
2019-01-14 21:27:06 +01:00
$responseSource1 = $this->requestedRight->getSource();
$responseSource2 = $this->requestedRight->getSource();
$this->assertEquals($responseSource1, $responseSource2);
2019-01-13 21:52:09 +01:00
}
public function testMetaEntity(): void
{
$slug = 123;
$source = $this->createMock(SourceInterface::class);
$entity = new Law();
$entity->setSource($source);
$requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('getSlug')->willReturn($slug);
$requestedEntity->method('hasSlug')->willReturn(true);
$requestedEntity->method('getEntity')->willReturn($entity);
2019-04-15 01:37:17 +02:00
$requestedEntity->method('hasIdentity')->willReturn(true);
$this->assertEquals($slug, $requestedEntity->getSlug());
$this->requestedRight->setRequestedEntity($requestedEntity);
$this->requestedRight->setLayer(LayerType::LAW);
$responseSource1 = $this->requestedRight->getSource();
$this->assertEquals($responseSource1, $source);
}
public function testSetActionType(): void
{
$attributType = ActionType::CREATE;
$this->requestedRight->setActionType($attributType);
$this->assertEquals($attributType, $this->requestedRight->getActionType());
2019-04-15 01:37:17 +02:00
$this->expectException(ContainsElementException::class);
$this->requestedRight->setActionType($attributType);
}
2019-01-13 21:52:09 +01:00
}