2018-10-31 15:19:24 +01:00
|
|
|
<?php
|
|
|
|
|
2018-10-31 16:15:39 +01:00
|
|
|
namespace tests\unit\Entity;
|
2018-10-31 15:19:24 +01:00
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use App\DBAL\Types\RightType;
|
2018-10-31 16:15:39 +01:00
|
|
|
use App\Entity\Meta\RightInterface;
|
|
|
|
use App\Entity\Meta\Right;
|
|
|
|
use App\Entity\Meta\Law;
|
2018-12-29 16:38:31 +01:00
|
|
|
use App\DBAL\Types\LayerType;
|
|
|
|
use App\Exception\NoValidChoice;
|
2018-12-29 23:01:57 +01:00
|
|
|
use App\Entity\Source\AbstractSource;
|
2018-10-31 15:19:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Implement reciever test
|
|
|
|
*
|
|
|
|
* @author kevinfrantz
|
|
|
|
*/
|
|
|
|
class RightTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var RightInterface
|
|
|
|
*/
|
2018-12-29 16:38:31 +01:00
|
|
|
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());
|
2018-11-24 14:59:15 +01:00
|
|
|
$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);
|
2018-10-31 15:19:24 +01:00
|
|
|
$this->assertNull($this->right->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLaw(): void
|
|
|
|
{
|
|
|
|
$law = new Law();
|
|
|
|
$this->assertNull($this->right->setLaw($law));
|
|
|
|
$this->assertEquals($law, $this->right->getLaw());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRight(): void
|
|
|
|
{
|
2018-12-29 16:38:31 +01:00
|
|
|
foreach (RightType::getChoices() as $key => $value) {
|
|
|
|
$this->assertNull($this->right->setType($key));
|
|
|
|
$this->assertEquals($key, $this->right->getType());
|
|
|
|
}
|
|
|
|
$this->expectException(NoValidChoice::class);
|
|
|
|
$this->right->setType('NoneValidType');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLayer(): void
|
|
|
|
{
|
|
|
|
foreach (LayerType::getChoices() as $key => $value) {
|
|
|
|
$this->assertNull($this->right->setLayer($key));
|
|
|
|
$this->assertEquals($key, $this->right->getLayer());
|
|
|
|
}
|
|
|
|
$this->expectException(NoValidChoice::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;
|
|
|
|
$type = RightType::READ;
|
|
|
|
$layer = LayerType::SOURCE;
|
|
|
|
$this->right->setSource($source);
|
|
|
|
$this->right->setReciever($reciever);
|
|
|
|
$this->right->setGrant($grant);
|
|
|
|
$this->right->setType($type);
|
|
|
|
$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->getType());
|
|
|
|
$this->assertEquals($layer, $rightClone->getLayer());
|
|
|
|
}
|
2018-10-31 15:19:24 +01:00
|
|
|
}
|