2019-01-13 21:52:09 +01:00
|
|
|
<?php
|
|
|
|
|
2019-05-30 16:52:02 +02:00
|
|
|
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;
|
2019-02-17 14:33:19 +01:00
|
|
|
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;
|
2019-05-30 16:52:02 +02:00
|
|
|
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;
|
2019-02-17 14:33:19 +01:00
|
|
|
use Infinito\Entity\Meta\Law;
|
2020-04-02 21:13:35 +02:00
|
|
|
use Infinito\Entity\Source\PureSource;
|
2019-02-17 14:33:19 +01:00
|
|
|
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);
|
2019-01-26 20:45:55 +01:00
|
|
|
$this->requestedRight->getLayer();
|
2019-01-13 21:52:09 +01:00
|
|
|
}
|
|
|
|
|
2019-01-20 12:54:56 +01:00
|
|
|
public function testRequestedEntityWithoutAttributes(): void
|
2019-01-13 21:52:09 +01:00
|
|
|
{
|
2019-01-20 12:54:56 +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
|
|
|
}
|
2019-01-26 20:45:55 +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);
|
2019-01-26 20:45:55 +01:00
|
|
|
$this->assertEquals($slug, $requestedEntity->getSlug());
|
|
|
|
$this->requestedRight->setRequestedEntity($requestedEntity);
|
|
|
|
$this->requestedRight->setLayer(LayerType::LAW);
|
|
|
|
$responseSource1 = $this->requestedRight->getSource();
|
|
|
|
$this->assertEquals($responseSource1, $source);
|
|
|
|
}
|
2019-02-26 19:49:19 +01:00
|
|
|
|
|
|
|
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);
|
2019-02-26 19:49:19 +01:00
|
|
|
$this->requestedRight->setActionType($attributType);
|
|
|
|
}
|
2019-01-13 21:52:09 +01:00
|
|
|
}
|