infinito/application/symfony/tests/Unit/Entity/Meta/RightTest.php

117 lines
3.4 KiB
PHP
Raw Normal View History

2018-10-31 15:19:24 +01:00
<?php
namespace tests\unit\Entity;
2018-10-31 15:19:24 +01:00
use Infinito\DBAL\Types\Meta\Right\CRUDType;
use Infinito\DBAL\Types\Meta\Right\LayerType;
2020-04-02 21:13:35 +02:00
use Infinito\Entity\Meta\Law;
use Infinito\Entity\Meta\Right;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Exception\Type\InvalidChoiceTypeException;
2020-04-02 21:13:35 +02:00
use PHPUnit\Framework\TestCase;
2018-10-31 15:19:24 +01:00
/**
* @todo Implement reciever test
*
* @author kevinfrantz
*/
class RightTest extends TestCase
{
/**
* @var RightInterface
*/
private $right;
2018-10-31 15:19:24 +01:00
public function setUp(): void
{
$this->right = new Right();
}
2018-11-06 20:56:54 +01:00
public function testConstructorGeneral(): void
2018-10-31 15:19:24 +01:00
{
2018-11-06 22:27:06 +01:00
$this->assertTrue($this->right->getGrant());
$this->assertEquals(0, $this->right->getPriority());
2018-11-06 22:42:24 +01:00
}
2018-12-14 10:10:28 +01:00
public function testConstructorReciever(): void
{
$this->expectException(\TypeError::class);
$this->right->getReciever();
}
2018-11-06 22:42:24 +01:00
public function testConstructorLayer(): void
{
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLayer());
}
public function testConstructorLaw(): void
{
2018-10-31 15:19:24 +01:00
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getLaw());
2018-11-06 20:56:54 +01:00
}
2018-11-06 22:42:24 +01:00
public function testConstructorCondition(): void
2018-11-06 20:56:54 +01:00
{
$this->expectException(\TypeError::class);
$this->right->getCondition();
}
public function testConstructorType(): void
{
2018-11-04 15:51:16 +01:00
$this->expectException(\TypeError::class);
$this->assertNull($this->right->getActionType());
2018-10-31 15:19:24 +01:00
}
public function testLaw(): void
{
$law = new Law();
$this->assertNull($this->right->setLaw($law));
$this->assertEquals($law, $this->right->getLaw());
}
public function testRight(): void
{
foreach (CRUDType::getValues() as $enum) {
$this->assertNull($this->right->setActionType($enum));
$this->assertEquals($enum, $this->right->getActionType());
}
$this->expectException(InvalidChoiceTypeException::class);
$this->right->setActionType('NoneValidType');
}
public function testLayer(): void
{
foreach (LayerType::getValues() as $choice) {
2019-01-16 21:47:41 +01:00
$this->assertNull($this->right->setLayer($choice));
$this->assertEquals($choice, $this->right->getLayer());
}
$this->expectException(InvalidChoiceTypeException::class);
$this->right->setLayer('NoneValidLayer');
2018-10-31 15:19:24 +01:00
}
2018-12-29 23:01:57 +01:00
/**
* Just to test if the clone function works like assumed.
*/
public function testClone(): void
{
$source = $this->createMock(AbstractSource::class);
$reciever = $this->createMock(AbstractSource::class);
$grant = false;
2019-01-05 17:27:40 +01:00
$type = CRUDType::READ;
2018-12-29 23:01:57 +01:00
$layer = LayerType::SOURCE;
$this->right->setSource($source);
$this->right->setReciever($reciever);
$this->right->setGrant($grant);
$this->right->setActionType($type);
2018-12-29 23:01:57 +01:00
$this->right->setLayer($layer);
$rightClone = clone $this->right;
$this->assertEquals($source, $rightClone->getSource());
$this->assertEquals($reciever, $rightClone->getReciever());
$this->assertEquals($grant, $rightClone->getGrant());
$this->assertEquals($type, $rightClone->getActionType());
2018-12-29 23:01:57 +01:00
$this->assertEquals($layer, $rightClone->getLayer());
}
2018-10-31 15:19:24 +01:00
}