2019-01-01 00:16:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\SecureLoadManagement;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
use Doctrine\Common\Persistence\ObjectRepository;
|
|
|
|
use App\Entity\Source\AbstractSource;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
|
use App\Domain\SecureLoadManagement\SecureSourceLoader;
|
|
|
|
use App\Entity\Source\Primitive\Text\TextSource;
|
|
|
|
use App\DBAL\Types\SystemSlugType;
|
|
|
|
use App\Entity\Meta\Right;
|
2019-01-05 17:27:40 +01:00
|
|
|
use App\DBAL\Types\Meta\Right\LayerType;
|
|
|
|
use App\DBAL\Types\Meta\Right\CRUDType;
|
2019-01-01 00:16:43 +01:00
|
|
|
use App\Entity\Source\Complex\UserSource;
|
|
|
|
use App\Entity\Source\Primitive\Text\TextSourceInterface;
|
2019-01-03 22:14:01 +01:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2019-01-01 00:16:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author kevinfrantz
|
|
|
|
*
|
|
|
|
* @todo Implement more tests
|
|
|
|
*/
|
|
|
|
class SecureSourceLoaderTest extends KernelTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ObjectRepository
|
|
|
|
*/
|
|
|
|
private $sourceRepository;
|
|
|
|
|
2019-01-03 22:14:01 +01:00
|
|
|
/**
|
|
|
|
* @var EntityManagerInterface
|
|
|
|
*/
|
|
|
|
private $entityManager;
|
|
|
|
|
2019-01-01 00:16:43 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
2019-01-03 22:14:01 +01:00
|
|
|
self::bootKernel();
|
|
|
|
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager');
|
|
|
|
$this->setSourceRepository();
|
2019-01-01 00:16:43 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 22:14:01 +01:00
|
|
|
private function setSourceRepository(): void
|
2019-01-01 00:16:43 +01:00
|
|
|
{
|
2019-01-03 22:14:01 +01:00
|
|
|
$this->sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
|
2019-01-01 00:16:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAccessDeniedException(): void
|
|
|
|
{
|
|
|
|
$requestedSource = new TextSource();
|
|
|
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
|
|
|
$requestedRight = new Right();
|
|
|
|
$requestedRight->setSource($requestedSource);
|
|
|
|
$requestedRight->setLayer(LayerType::SOURCE);
|
2019-01-05 17:27:40 +01:00
|
|
|
$requestedRight->setType(CRUDType::READ);
|
2019-01-01 00:16:43 +01:00
|
|
|
$requestedRight->setReciever(new UserSource());
|
2019-01-03 22:14:01 +01:00
|
|
|
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
|
2019-01-01 00:16:43 +01:00
|
|
|
$this->expectException(AccessDeniedHttpException::class);
|
|
|
|
$secureSourceLoader->getSource();
|
|
|
|
}
|
|
|
|
|
2019-01-01 22:36:55 +01:00
|
|
|
public function testGranted(): void
|
|
|
|
{
|
|
|
|
$requestedSource = new TextSource();
|
|
|
|
$requestedSource->setSlug(SystemSlugType::IMPRINT);
|
|
|
|
$requestedRight = new Right();
|
|
|
|
$requestedRight->setSource($requestedSource);
|
|
|
|
$requestedRight->setLayer(LayerType::SOURCE);
|
2019-01-05 17:27:40 +01:00
|
|
|
$requestedRight->setType(CRUDType::READ);
|
2019-01-04 20:10:08 +01:00
|
|
|
$requestedRight->setReciever($this->sourceRepository->findOneBySlug(SystemSlugType::GUEST_USER));
|
2019-01-03 22:14:01 +01:00
|
|
|
$secureSourceLoader = new SecureSourceLoader($this->entityManager, $requestedRight);
|
2019-01-01 22:36:55 +01:00
|
|
|
$this->assertInstanceOf(TextSourceInterface::class, $secureSourceLoader->getSource());
|
|
|
|
}
|
2019-01-01 00:16:43 +01:00
|
|
|
}
|