infinito/application/symfony/tests/Unit/Domain/Source/SourceRightManagerTest.php

83 lines
2.6 KiB
PHP
Raw Normal View History

2019-01-03 20:57:39 +01:00
<?php
namespace Unit\Domain\Source;
2019-01-03 20:57:39 +01:00
use PHPUnit\Framework\TestCase;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\Source\SourceRightManagerInterface;
use Infinito\Domain\Source\SourceRightManager;
use Infinito\Entity\Meta\RightInterface;
use Infinito\Entity\Meta\Right;
use Infinito\Entity\Meta\Law;
use Infinito\Entity\Source\PureSource;
2019-04-15 01:37:17 +02:00
use Infinito\Exception\Collection\ContainsElementException;
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
use Infinito\Exception\Collection\NotSetElementException;
2019-01-03 20:57:39 +01:00
2019-04-15 01:37:17 +02:00
/**
* @author kevinfrantz
*/
2019-01-03 20:57:39 +01:00
class SourceRightManagerTest extends TestCase
{
/**
* @var SourceInterface
*/
private $source;
/**
* @var SourceRightManagerInterface
*/
private $sourceRightManager;
/**
* @var RightInterface
*/
private $right;
public function setUp(): void
{
$this->source = new PureSource();
2019-01-03 20:57:39 +01:00
$this->sourceRightManager = new SourceRightManager($this->source);
$this->right = new Right();
}
public function testLawException(): void
{
$this->right->setLaw(new Law());
2019-04-15 01:37:17 +02:00
$this->expectException(AllreadyDefinedAttributException::class);
2019-01-03 20:57:39 +01:00
$this->sourceRightManager->addRight($this->right);
}
public function testSourceException(): void
{
$this->right->setSource(new PureSource());
2019-04-15 01:37:17 +02:00
$this->expectException(AllreadyDefinedAttributException::class);
2019-01-03 20:57:39 +01:00
$this->sourceRightManager->addRight($this->right);
}
2019-04-15 01:37:17 +02:00
public function testNotSetElementException(): void
2019-01-03 20:57:39 +01:00
{
2019-04-15 01:37:17 +02:00
$this->expectException(NotSetElementException::class);
2019-01-03 20:57:39 +01:00
$this->sourceRightManager->removeRight($this->right);
}
public function testAllreadSetException(): void
{
$this->sourceRightManager->addRight($this->right);
2019-04-15 01:37:17 +02:00
$this->expectException(ContainsElementException::class);
2019-01-03 20:57:39 +01:00
$this->sourceRightManager->addRight($this->right);
}
public function testRightAdd(): void
{
$this->assertNull($this->sourceRightManager->addRight($this->right));
$this->assertEquals($this->source, $this->right->getSource());
$this->assertEquals($this->right, $this->source->getLaw()->getRights()->get(0));
$this->assertEquals($this->right->getLaw(), $this->source->getLaw());
$this->assertNull($this->sourceRightManager->removeRight($this->right));
$this->assertNotEquals($this->source, $this->right->getSource());
$this->assertNotEquals($this->right->getLaw(), $this->source->getLaw());
$this->assertEquals(0, $this->source->getLaw()->getRights()->count());
}
}