mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Refactored draft for Request Management
This commit is contained in:
		@@ -0,0 +1,57 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement\Action;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Action\RequestedActionInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRight;
 | 
			
		||||
use App\Domain\RequestManagement\Action\RequestedAction;
 | 
			
		||||
use App\DBAL\Types\ActionType;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\CRUDType;
 | 
			
		||||
use App\Repository\Source\SourceRepositoryInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedActionTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedRightInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $requestedRight;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var RequestedActionInterface
 | 
			
		||||
     */
 | 
			
		||||
    private $action;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@inheritdoc}
 | 
			
		||||
     *
 | 
			
		||||
     * @see \PHPUnit\Framework\TestCase::setUp()
 | 
			
		||||
     */
 | 
			
		||||
    public function setUp(): void
 | 
			
		||||
    {
 | 
			
		||||
        $sourceRepository = $this->createMock(SourceRepositoryInterface::class);
 | 
			
		||||
        $this->requestedRight = new RequestedRight($sourceRepository);
 | 
			
		||||
        $this->action = new RequestedAction($this->requestedRight);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testList(): void
 | 
			
		||||
    {
 | 
			
		||||
        $list = ActionType::LIST;
 | 
			
		||||
        $this->action->setActionType($list);
 | 
			
		||||
        $this->assertEquals($list, $this->action->getActionType());
 | 
			
		||||
        $this->assertEquals(CRUDType::READ, $this->requestedRight->getCrud());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCrud(): void
 | 
			
		||||
    {
 | 
			
		||||
        foreach (CRUDType::getChoices() as $crud) {
 | 
			
		||||
            $this->action->setActionType($crud);
 | 
			
		||||
            $this->assertEquals($crud, $this->action->getActionType());
 | 
			
		||||
            $this->assertEquals($crud, $this->requestedRight->getCrud());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedUserRightService;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedUserRightServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRightServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedUserRightServiceTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructorSet(): void
 | 
			
		||||
    {
 | 
			
		||||
        $requestedRightService = $this->createMock(RequestedRightServiceInterface::class);
 | 
			
		||||
        $userSourceDirectorService = $this->createMock(UserSourceDirectorServiceInterface::class);
 | 
			
		||||
        $service = new RequestedUserRightService($userSourceDirectorService, $requestedRightService);
 | 
			
		||||
        $this->assertInstanceOf(RequestedUserRightServiceInterface::class, $service);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement;
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement\Entity;
 | 
			
		||||
 | 
			
		||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRight;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRight;
 | 
			
		||||
use App\Entity\Source\AbstractSource;
 | 
			
		||||
use App\DBAL\Types\Meta\Right\LayerType;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSource;
 | 
			
		||||
use App\Domain\RequestManagement\Entity\RequestedEntity;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
use App\Exception\PreconditionFailedException;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
 | 
			
		||||
@@ -44,19 +44,19 @@ class RequestedRightTest extends KernelTestCase
 | 
			
		||||
        var_dump($this->requestedRight->getLayer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRequestedSourceWithoutAttributes(): void
 | 
			
		||||
    public function testRequestedEntityWithoutAttributes(): void
 | 
			
		||||
    {
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedSource::class);
 | 
			
		||||
        $this->requestedRight->setRequestedSource($requestedSource);
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedEntity::class);
 | 
			
		||||
        $this->requestedRight->setRequestedEntity($requestedSource);
 | 
			
		||||
        $this->expectException(PreconditionFailedException::class);
 | 
			
		||||
        $this->requestedRight->getSource();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testKnownSource(): void
 | 
			
		||||
    {
 | 
			
		||||
        $requestedSource = new RequestedSource();
 | 
			
		||||
        $requestedSource = new RequestedEntity();
 | 
			
		||||
        $requestedSource->setSlug(SystemSlugType::IMPRINT);
 | 
			
		||||
        $this->requestedRight->setRequestedSource($requestedSource);
 | 
			
		||||
        $this->requestedRight->setRequestedEntity($requestedSource);
 | 
			
		||||
        $sourceResponse1 = $this->requestedRight->getSource();
 | 
			
		||||
        $this->assertGreaterThan(0, $sourceResponse1->getId());
 | 
			
		||||
        $requestedSource->setSlug('');
 | 
			
		||||
@@ -67,11 +67,11 @@ class RequestedRightTest extends KernelTestCase
 | 
			
		||||
    public function testEqualsSlug(): void
 | 
			
		||||
    {
 | 
			
		||||
        $slug = SystemSlugType::IMPRINT;
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedSourceInterface::class);
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedEntityInterface::class);
 | 
			
		||||
        $requestedSource->method('getSlug')->willReturn($slug);
 | 
			
		||||
        $requestedSource->method('hasSlug')->willReturn(true);
 | 
			
		||||
        $this->assertEquals($slug, $requestedSource->getSlug());
 | 
			
		||||
        $this->requestedRight->setRequestedSource($requestedSource);
 | 
			
		||||
        $this->requestedRight->setRequestedEntity($requestedSource);
 | 
			
		||||
        $responseSource1 = $this->requestedRight->getSource();
 | 
			
		||||
        $responseSource2 = $this->requestedRight->getSource();
 | 
			
		||||
        $this->assertEquals($responseSource1, $responseSource2);
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RequestManagement\User;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Domain\RequestManagement\User\RequestedUserService;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirectorServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\User\RequestedUserServiceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRightServiceInterface;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedUserServiceTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testConstructorSet(): void
 | 
			
		||||
    {
 | 
			
		||||
        $requestedRightService = $this->createMock(RequestedRightServiceInterface::class);
 | 
			
		||||
        $userSourceDirectorService = $this->createMock(UserSourceDirectorServiceInterface::class);
 | 
			
		||||
        $service = new RequestedUserService($userSourceDirectorService, $requestedRightService);
 | 
			
		||||
        $this->assertInstanceOf(RequestedUserServiceInterface::class, $service);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,19 +1,19 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace tests\Unit\Domain\RightManagement;
 | 
			
		||||
namespace tests\Unit\Domain\RightManagement\User;
 | 
			
		||||
 | 
			
		||||
use PHPUnit\Framework\TestCase;
 | 
			
		||||
use App\Entity\User;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedUserRight;
 | 
			
		||||
use App\Domain\RequestManagement\User\RequestedUser;
 | 
			
		||||
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\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedRight;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRightInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Right\RequestedRight;
 | 
			
		||||
use App\Domain\UserManagement\UserSourceDirector;
 | 
			
		||||
use App\Repository\Source\SourceRepositoryInterface;
 | 
			
		||||
use App\Domain\RequestManagement\RequestedSourceInterface;
 | 
			
		||||
use App\Domain\RequestManagement\Entity\RequestedEntityInterface;
 | 
			
		||||
use App\DBAL\Types\SystemSlugType;
 | 
			
		||||
use App\Exception\NotSetException;
 | 
			
		||||
use App\Exception\SetNotPossibleException;
 | 
			
		||||
@@ -21,13 +21,13 @@ use App\Exception\SetNotPossibleException;
 | 
			
		||||
/**
 | 
			
		||||
 * @author kevinfrantz
 | 
			
		||||
 */
 | 
			
		||||
class RequestedUserRightTest extends TestCase
 | 
			
		||||
class RequestedUserTest extends TestCase
 | 
			
		||||
{
 | 
			
		||||
    public function testInterface(): void
 | 
			
		||||
    {
 | 
			
		||||
        $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
 | 
			
		||||
        $requestedRight = $this->createMock(RequestedRightInterface::class);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertInstanceOf(RequestedRightInterface::class, $requestedUserRightFacade);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -46,7 +46,7 @@ class RequestedUserRightTest extends TestCase
 | 
			
		||||
        $requestedRight->method('getLayer')->willReturn($layer);
 | 
			
		||||
        $requestedRight->method('getCrud')->willReturn($type);
 | 
			
		||||
        $requestedRight->method('getSource')->willReturn($source);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertEquals($layer, $requestedUserRightFacade->getLayer());
 | 
			
		||||
        $this->assertEquals($type, $requestedUserRightFacade->getCrud());
 | 
			
		||||
        $this->assertEquals($source, $requestedUserRightFacade->getSource());
 | 
			
		||||
@@ -57,21 +57,21 @@ class RequestedUserRightTest extends TestCase
 | 
			
		||||
    {
 | 
			
		||||
        $layer = LayerType::SOURCE;
 | 
			
		||||
        $type = CRUDType::READ;
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedSourceInterface::class);
 | 
			
		||||
        $requestedSource = $this->createMock(RequestedEntityInterface::class);
 | 
			
		||||
        $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT);
 | 
			
		||||
        $requestedSource->method('hasSlug')->willReturn(true);
 | 
			
		||||
        $sourceRepository = $this->createMock(SourceRepositoryInterface::class);
 | 
			
		||||
        $requestedRight = new RequestedRight($sourceRepository);
 | 
			
		||||
        $user = $this->createMock(User::class);
 | 
			
		||||
        $userSourceDirector = new UserSourceDirector($sourceRepository, $user);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setLayer($layer));
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setCrud($type));
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setRequestedSource($requestedSource));
 | 
			
		||||
        $this->assertNull($requestedUserRightFacade->setRequestedEntity($requestedSource));
 | 
			
		||||
        $this->assertEquals($layer, $requestedRight->getLayer());
 | 
			
		||||
        $this->assertEquals($type, $requestedRight->getCrud());
 | 
			
		||||
        $this->expectException(NotSetException::class);
 | 
			
		||||
        $this->assertNotInstanceOf(RequestedSourceInterface::class, $requestedRight->getSource());
 | 
			
		||||
        $this->assertNotInstanceOf(RequestedEntityInterface::class, $requestedRight->getSource());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testSetReciever(): void
 | 
			
		||||
@@ -79,7 +79,7 @@ class RequestedUserRightTest extends TestCase
 | 
			
		||||
        $reciever = $this->createMock(AbstractSource::class);
 | 
			
		||||
        $userSourceDirector = $this->createMock(UserSourceDirectorInterface::class);
 | 
			
		||||
        $requestedRight = $this->createMock(RequestedRightInterface::class);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUserRight($userSourceDirector, $requestedRight);
 | 
			
		||||
        $requestedUserRightFacade = new RequestedUser($userSourceDirector, $requestedRight);
 | 
			
		||||
        $this->expectException(SetNotPossibleException::class);
 | 
			
		||||
        $requestedUserRightFacade->setReciever($reciever);
 | 
			
		||||
    }
 | 
			
		||||
		Reference in New Issue
	
	Block a user