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

87 lines
4.1 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 App\Entity\User;
use App\Domain\RequestManagement\User\RequestedUser;
2019-01-15 22:57:54 +01:00
use App\DBAL\Types\Meta\Right\LayerType;
use App\DBAL\Types\Meta\Right\CRUDType;
use App\Entity\Source\AbstractSource;
use App\Domain\UserManagement\UserSourceDirectorInterface;
use App\Domain\RequestManagement\Right\RequestedRightInterface;
use App\Domain\RequestManagement\Right\RequestedRight;
2019-01-15 22:57:54 +01:00
use App\Domain\UserManagement\UserSourceDirector;
use App\Repository\Source\SourceRepositoryInterface;
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
2019-01-15 22:57:54 +01:00
use App\DBAL\Types\SystemSlugType;
use App\Exception\SetNotPossibleException;
2019-01-26 19:39:36 +01:00
use App\Exception\NotCorrectInstanceException;
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);
2019-01-16 21:22:18 +01:00
$requestedRight->method('getCrud')->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());
2019-01-16 21:22:18 +01:00
$this->assertEquals($type, $requestedUserRightFacade->getCrud());
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;
$requestedSource = $this->createMock(RequestedEntityInterface::class);
2019-01-15 22:57:54 +01:00
$requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
$requestedSource->method('hasSlug')->willReturn(true);
$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));
2019-01-16 21:22:18 +01:00
$this->assertNull($requestedUserRightFacade->setCrud($type));
$this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedSource));
2019-01-15 22:57:54 +01:00
$this->assertEquals($layer, $requestedRight->getLayer());
2019-01-16 21:22:18 +01:00
$this->assertEquals($type, $requestedRight->getCrud());
2019-01-26 19:39:36 +01:00
$this->expectException(NotCorrectInstanceException::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-01-15 22:57:54 +01:00
$this->expectException(SetNotPossibleException::class);
$requestedUserRightFacade->setReciever($reciever);
}
}