infinito/application/symfony/tests/Unit/Domain/RequestManagement/User/RequestedUserRightTest.php

96 lines
4.8 KiB
PHP
Raw Normal View History

2019-01-15 22:57:54 +01:00
<?php
namespace tests\Unit\Domain\RightManagement\User;
2019-01-15 22:57:54 +01:00
use PHPUnit\Framework\TestCase;
use Infinito\Entity\User;
use Infinito\Domain\RequestManagement\User\RequestedUser;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\DBAL\Types\Meta\Right\CRUDType;
use Infinito\Entity\Source\AbstractSource;
use Infinito\Domain\UserManagement\UserSourceDirectorInterface;
use Infinito\Domain\RequestManagement\Right\RequestedRightInterface;
use Infinito\Domain\RequestManagement\Right\RequestedRight;
use Infinito\Domain\UserManagement\UserSourceDirector;
use Infinito\Repository\Source\SourceRepositoryInterface;
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
use Infinito\Domain\Fixture\FixtureSource\ImpressumFixtureSource;
2019-04-15 01:37:17 +02:00
use Infinito\Exception\Core\NotCorrectInstanceCoreException;
use Infinito\Exception\Collection\NotPossibleSetElementException;
2019-01-15 22:57:54 +01:00
/**
* @author kevinfrantz
*/
class RequestedUserTest extends TestCase
2019-01-15 22:57:54 +01:00
{
public function testInterface(): void
{
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
2019-01-15 22:57:54 +01:00
$this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade);
}
public function testGetters(): void
{
$reciever = $this->createMock(AbstractSource::class);
$user = $this->createMock(User::class);
$user->method('getSource')->willReturn($reciever);
$layer = LayerType::SOURCE;
$type = CRUDType::READ;
$source = $this->createMock(AbstractSource::class);
$reciever = $this->createMock(AbstractSource::class);
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$userSourceDirector->method('getUser')->willReturn($user);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedRight->method('getLayer')->willReturn($layer);
$requestedRight->method('getActionType')->willReturn($type);
2019-01-15 22:57:54 +01:00
$requestedRight->method('getSource')->willReturn($source);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
2019-01-15 22:57:54 +01:00
$this->assertEquals($layer, $requestedUserRightFacade->getLayer());
$this->assertEquals($type, $requestedUserRightFacade->getActionType());
2019-01-15 22:57:54 +01:00
$this->assertEquals($source, $requestedUserRightFacade->getSource());
$this->assertEquals($reciever, $requestedUserRightFacade->getReciever());
}
public function testSetters(): void
{
$layer = LayerType::SOURCE;
$type = CRUDType::READ;
2019-04-15 01:37:17 +02:00
$requestedEntitySource = $this->createMock(RequestedEntityInterface::class);
$requestedEntitySource->method('getSlug')->willReturn(ImpressumFixtureSource::getSlug());
$requestedEntitySource->method('hasSlug')->willReturn(true);
$requestedEntitySource->method('hasIdentity')->willReturn(true);
2019-01-15 22:57:54 +01:00
$sourceRepository = $this->createMock(SourceRepositoryInterface::class);
2019-01-26 19:39:36 +01:00
$requestedRight = new RequestedRight();
2019-01-15 22:57:54 +01:00
$user = $this->createMock(User::class);
$userSourceDirector = new UserSourceDirector($sourceRepository, $user);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
2019-01-15 22:57:54 +01:00
$this->assertNull($requestedUserRightFacade->setLayer($layer));
$this->assertNull($requestedUserRightFacade->setActionType($type));
2019-04-15 01:37:17 +02:00
$this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedEntitySource));
2019-01-15 22:57:54 +01:00
$this->assertEquals($layer, $requestedRight->getLayer());
$this->assertEquals($type, $requestedRight->getActionType());
2019-04-15 01:37:17 +02:00
$this->expectException(NotCorrectInstanceCoreException::class);
$this->assertNotInstanceOf(RequestedEntityInterface::class, $requestedRight->getSource());
2019-01-15 22:57:54 +01:00
}
public function testSetReciever(): void
{
$reciever = $this->createMock(AbstractSource::class);
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
2019-04-15 01:37:17 +02:00
$this->expectException(NotPossibleSetElementException::class);
2019-01-15 22:57:54 +01:00
$requestedUserRightFacade->setReciever($reciever);
}
2019-02-13 15:09:03 +01:00
public function testGetUserDirector(): void
{
$userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
$requestedRight = $this->createMock(RequestedRightInterface::class);
$requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
$this->assertEquals($userSourceDirector, $requestedUserRightFacade->getUserSourceDirector());
}
2019-01-15 22:57:54 +01:00
}