Optimized FixtureSources and menu

This commit is contained in:
Kevin Frantz 2019-03-29 23:21:52 +01:00
parent 4280489499
commit db2e4dac01
18 changed files with 195 additions and 88 deletions

View File

@ -21,7 +21,7 @@ final class DefaultController extends AbstractController
public function homepage(): Response public function homepage(): Response
{ {
return $this->redirectToRoute('infinito_api_rest_layer_read', [ return $this->redirectToRoute('infinito_api_rest_layer_read', [
'identity' => HomepageFixtureSource::SLUG, 'identity' => HomepageFixtureSource::getSlug(),
'layer' => LayerType::SOURCE, 'layer' => LayerType::SOURCE,
'_format' => RESTResponseType::HTML, '_format' => RESTResponseType::HTML,
]); ]);

View File

@ -0,0 +1,30 @@
<?php
namespace Infinito\Domain\FixtureManagement;
use Infinito\Entity\Meta\Right;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\DBAL\Types\ActionType;
use Infinito\Entity\Source\SourceInterface;
/**
* @author kevinfrantz
*/
final class EntityTemplateFactory extends Right
{
/**
* @param SourceInterface $source
*/
public static function createStandartPublicRight(SourceInterface $source): Right
{
$right = new Right();
$law = $source->getLaw();
$right->setLaw($law);
$law->getRights()->add($right);
$right->setSource($source);
$right->setLayer(LayerType::SOURCE);
$right->setActionType(ActionType::READ);
return $right;
}
}

View File

@ -9,4 +9,17 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
*/ */
abstract class AbstractFixtureSource implements FixtureSourceInterface abstract class AbstractFixtureSource implements FixtureSourceInterface
{ {
/**
* @return string
*/
public static function getSlug(): string
{
$className = get_called_class();
$exploded = explode('\\', $className);
$shortname = $exploded[count($exploded) - 1];
$key = str_replace('FixtureSource', '', $shortname);
$lower = strtolower($key);
return $lower;
}
} }

View File

@ -23,4 +23,11 @@ interface FixtureSourceInterface
* @return SlugAttributInterface * @return SlugAttributInterface
*/ */
public static function getSlug(): string; public static function getSlug(): string;
/**
* @see https://fontawesome.com
*
* @return string|null a fontawesome css class
*/
public static function getIcon(): string;
} }

View File

@ -4,6 +4,7 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
use Infinito\Entity\Source\SourceInterface; use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Source\Complex\UserSource; use Infinito\Entity\Source\Complex\UserSource;
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
/** /**
* This class containes the guest user. * This class containes the guest user.
@ -12,8 +13,6 @@ use Infinito\Entity\Source\Complex\UserSource;
*/ */
final class GuestUserFixtureSource extends AbstractFixtureSource final class GuestUserFixtureSource extends AbstractFixtureSource
{ {
const SLUG = 'GUEST_USER';
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
@ -22,7 +21,8 @@ final class GuestUserFixtureSource extends AbstractFixtureSource
public function getORMReadyObject(): SourceInterface public function getORMReadyObject(): SourceInterface
{ {
$userSource = new UserSource(); $userSource = new UserSource();
$userSource->setSlug(self::SLUG); $userSource->setSlug(self::getSlug());
EntityTemplateFactory::createStandartPublicRight($userSource);
return $userSource; return $userSource;
} }
@ -30,8 +30,8 @@ final class GuestUserFixtureSource extends AbstractFixtureSource
/** /**
* @return string * @return string
*/ */
public static function getSlug(): string public static function getIcon(): string
{ {
return self::SLUG; return 'fas fa-user';
} }
} }

View File

@ -0,0 +1,36 @@
<?php
namespace Infinito\Domain\FixtureManagement\FixtureSource;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Source\Primitive\Text\TextSource;
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
/**
* @author kevinfrantz
*/
final class HelpFixtureSource extends AbstractFixtureSource
{
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\FixtureManagement\FixtureSource\FixtureSourceInterface::getORMReadyObject()
*/
public function getORMReadyObject(): SourceInterface
{
$helpSource = new TextSource();
$helpSource->setText('See https://github.com/KevinFrantz/infinito/issues.');
$helpSource->setSlug(self::getSlug());
EntityTemplateFactory::createStandartPublicRight($helpSource);
return $helpSource;
}
/**
* @return string
*/
public static function getIcon(): string
{
return 'fas fa-question';
}
}

View File

@ -4,20 +4,13 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
use Infinito\Entity\Source\SourceInterface; use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Source\Primitive\Text\TextSource; use Infinito\Entity\Source\Primitive\Text\TextSource;
use Infinito\Entity\Meta\Right; use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\DBAL\Types\ActionType;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
final class HomepageFixtureSource extends AbstractFixtureSource final class HomepageFixtureSource extends AbstractFixtureSource
{ {
/**
* @var string
*/
const SLUG = 'HOMEPAGE';
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
@ -25,24 +18,16 @@ final class HomepageFixtureSource extends AbstractFixtureSource
*/ */
public function getORMReadyObject(): SourceInterface public function getORMReadyObject(): SourceInterface
{ {
$impressumSource = new TextSource(); $homepage = new TextSource();
$impressumSource->setText('Welcome to infinito!'); $homepage->setText('Welcome to infinito!');
$impressumSource->setSlug(self::SLUG); $homepage->setSlug(self::getSlug());
$right = new Right(); EntityTemplateFactory::createStandartPublicRight($homepage);
$right->setSource($impressumSource);
$right->setLayer(LayerType::SOURCE);
$right->setActionType(ActionType::READ);
$right->setLaw($impressumSource->getLaw());
$impressumSource->getLaw()->getRights()->add($right);
return $impressumSource; return $homepage;
} }
/** public static function getIcon(): string
* @return string
*/
public static function getSlug(): string
{ {
return self::SLUG; return 'fas fa-home';
} }
} }

View File

@ -4,17 +4,13 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
use Infinito\Entity\Source\SourceInterface; use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Source\Primitive\Text\TextSource; use Infinito\Entity\Source\Primitive\Text\TextSource;
use Infinito\Entity\Meta\Right; use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\DBAL\Types\ActionType;
/** /**
* @author kevinfrantz * @author kevinfrantz
*/ */
final class ImpressumFixtureSource extends AbstractFixtureSource final class ImpressumFixtureSource extends AbstractFixtureSource
{ {
const SLUG = 'IMPRINT';
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
@ -24,13 +20,8 @@ final class ImpressumFixtureSource extends AbstractFixtureSource
{ {
$impressumSource = new TextSource(); $impressumSource = new TextSource();
$impressumSource->setText('Example Impressum'); $impressumSource->setText('Example Impressum');
$impressumSource->setSlug(self::SLUG); $impressumSource->setSlug(self::getSlug());
$right = new Right(); EntityTemplateFactory::createStandartPublicRight($impressumSource);
$right->setSource($impressumSource);
$right->setLayer(LayerType::SOURCE);
$right->setActionType(ActionType::READ);
$right->setLaw($impressumSource->getLaw());
$impressumSource->getLaw()->getRights()->add($right);
return $impressumSource; return $impressumSource;
} }
@ -38,8 +29,8 @@ final class ImpressumFixtureSource extends AbstractFixtureSource
/** /**
* @return string * @return string
*/ */
public static function getSlug(): string public static function getIcon(): string
{ {
return self::SLUG; return 'fas fa-address-card';
} }
} }

View File

@ -0,0 +1,36 @@
<?php
namespace Infinito\Domain\FixtureManagement\FixtureSource;
use Infinito\Entity\Source\SourceInterface;
use Infinito\Entity\Source\Primitive\Text\TextSource;
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
/**
* @author kevinfrantz
*/
final class InformationFixtureSource extends AbstractFixtureSource
{
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\FixtureManagement\FixtureSource\FixtureSourceInterface::getORMReadyObject()
*/
public function getORMReadyObject(): SourceInterface
{
$informationSource = new TextSource();
$informationSource->setText('See https://github.com/KevinFrantz/infinito/issues.');
$informationSource->setSlug(self::getSlug());
EntityTemplateFactory::createStandartPublicRight($informationSource);
return $informationSource;
}
/**
* @return string
*/
public static function getIcon(): string
{
return 'fas fa-info';
}
}

View File

@ -8,13 +8,12 @@ use Symfony\Component\Translation\TranslatorInterface;
use Knp\Menu\ItemInterface; use Knp\Menu\ItemInterface;
use Infinito\Event\Menu\MenuEvent; use Infinito\Event\Menu\MenuEvent;
use Infinito\DBAL\Types\MenuEventType; use Infinito\DBAL\Types\MenuEventType;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Infinito\DBAL\Types\RESTResponseType; use Infinito\DBAL\Types\RESTResponseType;
use Infinito\DBAL\Types\Meta\Right\LayerType; use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Controller\API\Rest\LayerController; use Infinito\Controller\API\Rest\LayerController;
use Infinito\Domain\FixtureManagement\FixtureSource\HomepageFixtureSource; use Infinito\Domain\FixtureManagement\FixtureSourceFactory;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -52,29 +51,22 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
public function onUserMenuConfigure(MenuEvent $event): void public function onUserMenuConfigure(MenuEvent $event): void
{ {
$menu = $event->getItem(); $menu = $event->getItem();
$menu->addChild($this->trans('home'), [ $fixtureSources = FixtureSourceFactory::getAllFixtureSources();
'route' => self::LAYER_GET_ROUTE, foreach ($fixtureSources as $fixtureSource) {
'routeParameters' => [ $slug = $fixtureSource::getSlug();
'identity' => HomepageFixtureSource::getSlug(), $icon = $fixtureSource::getIcon();
'_format' => RESTResponseType::HTML, $menu->addChild($this->trans($slug), [
'layer' => LayerType::SOURCE, 'route' => self::LAYER_GET_ROUTE,
], 'routeParameters' => [
'attributes' => [ 'identity' => $slug,
'icon' => 'fas fa-home', '_format' => RESTResponseType::HTML,
], 'layer' => LayerType::SOURCE,
]); ],
'attributes' => [
$menu->addChild($this->trans('imprint'), [ 'icon' => $icon,
'route' => self::LAYER_GET_ROUTE, ],
'routeParameters' => [ ]);
'identity' => ImpressumFixtureSource::getSlug(), }
'_format' => RESTResponseType::HTML,
'layer' => LayerType::SOURCE,
],
'attributes' => [
'icon' => 'fas fa-address-card',
],
]);
if ($this->shouldShowFormatSelection($event)) { if ($this->shouldShowFormatSelection($event)) {
$this->generateShowDropdown($menu, $event, self::LAYER_GET_ROUTE); $this->generateShowDropdown($menu, $event, self::LAYER_GET_ROUTE);
} }
@ -169,7 +161,10 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
*/ */
private function shouldShowFormatSelection(Event $event): bool private function shouldShowFormatSelection(Event $event): bool
{ {
foreach ([LayerController::IDENTITY_PARAMETER_KEY, LayerController::LAYER_PARAMETER_KEY] as $key) { foreach ([
LayerController::IDENTITY_PARAMETER_KEY,
LayerController::LAYER_PARAMETER_KEY,
] as $key) {
$attributs = $this->getRequestAttributs($event); $attributs = $this->getRequestAttributs($event);
if (!key_exists($key, $attributs) || '' === $attributs[$key]) { if (!key_exists($key, $attributs) || '' === $attributs[$key]) {
return false; return false;

View File

@ -5,6 +5,7 @@ namespace Tests\Functional;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Bundle\FrameworkBundle\Client;
use Infinito\Domain\FixtureManagement\FixtureSource\HomepageFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -16,14 +17,25 @@ class FormatFunctionTest extends WebTestCase
*/ */
private $client; private $client;
/**
* @var string
*/
private $identity;
/**
* {@inheritdoc}
*
* @see \PHPUnit\Framework\TestCase::setUp()
*/
public function setUp(): void public function setUp(): void
{ {
$this->client = static::createClient(); $this->client = static::createClient();
$this->identity = HomepageFixtureSource::getSlug();
} }
public function testHomepage(): void public function testHomepage(): void
{ {
$this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE'); $this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity);
$this->assertEquals(200, $this->client->getResponse() $this->assertEquals(200, $this->client->getResponse()
->getStatusCode()); ->getStatusCode());
$this->assertJson($this->client->getResponse() $this->assertJson($this->client->getResponse()
@ -32,7 +44,7 @@ class FormatFunctionTest extends WebTestCase
public function testHomepageWithHTML(): void public function testHomepageWithHTML(): void
{ {
$this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.html'); $this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.html');
$this->assertEquals(200, $this->client->getResponse() $this->assertEquals(200, $this->client->getResponse()
->getStatusCode()); ->getStatusCode());
$this->assertContains('<html', $this->client->getResponse() $this->assertContains('<html', $this->client->getResponse()
@ -41,7 +53,7 @@ class FormatFunctionTest extends WebTestCase
public function testHomepageWithJSON(): void public function testHomepageWithJSON(): void
{ {
$this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.json'); $this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.json');
$this->assertEquals(200, $this->client->getResponse() $this->assertEquals(200, $this->client->getResponse()
->getStatusCode()); ->getStatusCode());
$this->assertJson($this->client->getResponse() $this->assertJson($this->client->getResponse()
@ -50,7 +62,7 @@ class FormatFunctionTest extends WebTestCase
public function testHomepageWithXML(): void public function testHomepageWithXML(): void
{ {
$this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.xml'); $this->client->request(Request::METHOD_GET, 'api/rest/source/'.$this->identity.'.xml');
$this->assertEquals(200, $this->client->getResponse() $this->assertEquals(200, $this->client->getResponse()
->getStatusCode()); ->getStatusCode());
$content = $this->client->getResponse()->getContent(); $content = $this->client->getResponse()->getContent();

View File

@ -30,14 +30,14 @@ class SourceFixturesIntegrationTest extends KernelTestCase
public function testImpressumSource(): void public function testImpressumSource(): void
{ {
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class); $sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
$imprint = $sourceRepository->findOneBySlug(ImpressumFixtureSource::SLUG); $imprint = $sourceRepository->findOneBySlug(ImpressumFixtureSource::getSlug());
$this->assertInternalType('string', $imprint->getText()); $this->assertInternalType('string', $imprint->getText());
} }
public function testGuestUserSource(): void public function testGuestUserSource(): void
{ {
$sourceRepository = $this->entityManager->getRepository(AbstractSource::class); $sourceRepository = $this->entityManager->getRepository(AbstractSource::class);
$userSource = $sourceRepository->findOneBySlug(GuestUserFixtureSource::SLUG); $userSource = $sourceRepository->findOneBySlug(GuestUserFixtureSource::getSlug());
$this->assertInstanceOf(UserSourceInterface::class, $userSource); $this->assertInstanceOf(UserSourceInterface::class, $userSource);
} }
} }

View File

@ -37,9 +37,9 @@ class ActionHandlerServiceIntegrationTest extends KernelTestCase
$this->requestedActionService = self::$container->get(RequestedActionServiceInterface::class); $this->requestedActionService = self::$container->get(RequestedActionServiceInterface::class);
} }
public function testEnityManager(): void public function testEntityManager(): void
{ {
$this->requestedActionService->getRequestedEntity()->setSlug(ImpressumFixtureSource::SLUG); $this->requestedActionService->getRequestedEntity()->setSlug(ImpressumFixtureSource::getSlug());
$this->requestedActionService->setActionType(ActionType::READ); $this->requestedActionService->setActionType(ActionType::READ);
$this->requestedActionService->setLayer(LayerType::SOURCE); $this->requestedActionService->setLayer(LayerType::SOURCE);
$this->assertInstanceOf(SourceInterface::class, $this->actionHandlerService->handle()); $this->assertInstanceOf(SourceInterface::class, $this->actionHandlerService->handle());

View File

@ -4,6 +4,7 @@ namespace tests\Integration\Domain\FixtureManagement;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -23,7 +24,7 @@ class ImprintFixtureSourceTest extends KernelTestCase
public function testImprintSourceReachable(): void public function testImprintSourceReachable(): void
{ {
$request = new Request([], [], [], [], [], [ $request = new Request([], [], [], [], [], [
'REQUEST_URI' => 'api/rest/source/imprint.html', 'REQUEST_URI' => 'api/rest/source/'.ImpressumFixtureSource::getSlug().'.html',
]); ]);
$request->setMethod(Request::METHOD_GET); $request->setMethod(Request::METHOD_GET);
$response = static::$kernel->handle($request); $response = static::$kernel->handle($request);

View File

@ -5,6 +5,7 @@ namespace Infinito\Tests\Unit\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Infinito\Controller\DefaultController; use Infinito\Controller\DefaultController;
use Infinito\DBAL\Types\RESTResponseType; use Infinito\DBAL\Types\RESTResponseType;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -34,7 +35,7 @@ class DefaultControllerTest extends WebTestCase
$client = static::createClient(); $client = static::createClient();
foreach (RESTResponseType::getValues() as $format) { foreach (RESTResponseType::getValues() as $format) {
$format = 'html'; $format = 'html';
$url = '/api/rest/source/imprint.'.$format; $url = '/api/rest/source/'.ImpressumFixtureSource::getSlug().'.'.$format;
$client->request('GET', $url); $client->request('GET', $url);
$this->assertEquals(200, $client->getResponse() $this->assertEquals(200, $client->getResponse()
->getStatusCode(), "Route $url is not reachable."); ->getStatusCode(), "Route $url is not reachable.");

View File

@ -1,13 +1,12 @@
<?php <?php
namespace tests\Unit\Domain\RequestManagement\Entity; namespace tests\Unit\Domain\RequestManagement\Right;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Infinito\Domain\RequestManagement\Right\RequestedRightInterface; use Infinito\Domain\RequestManagement\Right\RequestedRightInterface;
use Infinito\Domain\RequestManagement\Right\RequestedRight; use Infinito\Domain\RequestManagement\Right\RequestedRight;
use Infinito\DBAL\Types\Meta\Right\LayerType; use Infinito\DBAL\Types\Meta\Right\LayerType;
use Infinito\Domain\RequestManagement\Entity\RequestedEntity; use Infinito\Domain\RequestManagement\Entity\RequestedEntity;
use Infinito\DBAL\Types\SystemSlugType;
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface; use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
use Infinito\Exception\PreconditionFailedException; use Infinito\Exception\PreconditionFailedException;
use Infinito\Entity\Source\PureSource; use Infinito\Entity\Source\PureSource;
@ -18,6 +17,7 @@ use Infinito\Entity\Meta\Law;
use Infinito\Entity\Source\SourceInterface; use Infinito\Entity\Source\SourceInterface;
use Infinito\DBAL\Types\ActionType; use Infinito\DBAL\Types\ActionType;
use Infinito\Exception\AllreadySetException; use Infinito\Exception\AllreadySetException;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -66,7 +66,7 @@ class RequestedRightTest extends KernelTestCase
public function testKnownSource(): void public function testKnownSource(): void
{ {
$requestedEntity = new RequestedEntity($this->layerRepositoryFactoryService); $requestedEntity = new RequestedEntity($this->layerRepositoryFactoryService);
$requestedEntity->setSlug(SystemSlugType::IMPRINT); $requestedEntity->setSlug(ImpressumFixtureSource::getSlug());
$this->requestedRight->setRequestedEntity($requestedEntity); $this->requestedRight->setRequestedEntity($requestedEntity);
$this->requestedRight->setLayer(LayerType::SOURCE); $this->requestedRight->setLayer(LayerType::SOURCE);
$sourceResponse1 = $this->requestedRight->getSource(); $sourceResponse1 = $this->requestedRight->getSource();
@ -78,7 +78,7 @@ class RequestedRightTest extends KernelTestCase
public function testEqualsSlug(): void public function testEqualsSlug(): void
{ {
$slug = SystemSlugType::IMPRINT; $slug = ImpressumFixtureSource::getSlug();
$requestedEntityEntity = new PureSource(); $requestedEntityEntity = new PureSource();
$requestedEntity = $this->createMock(RequestedEntityInterface::class); $requestedEntity = $this->createMock(RequestedEntityInterface::class);
$requestedEntity->method('getSlug')->willReturn($slug); $requestedEntity->method('getSlug')->willReturn($slug);

View File

@ -3,11 +3,11 @@
namespace Tests\Unit\Domain\UserManagement; namespace Tests\Unit\Domain\UserManagement;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Infinito\DBAL\Types\SystemSlugType;
use Infinito\Entity\User; use Infinito\Entity\User;
use Infinito\Domain\UserManagement\UserSourceDirector; use Infinito\Domain\UserManagement\UserSourceDirector;
use Infinito\Repository\Source\SourceRepository; use Infinito\Repository\Source\SourceRepository;
use Infinito\Entity\Source\AbstractSource; use Infinito\Entity\Source\AbstractSource;
use Infinito\Domain\FixtureManagement\FixtureSource\GuestUserFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -30,7 +30,7 @@ class UserSourceDirectorTest extends KernelTestCase
$origineUser = null; $origineUser = null;
$userIdentityManager = new UserSourceDirector($this->sourceRepository, $origineUser); $userIdentityManager = new UserSourceDirector($this->sourceRepository, $origineUser);
$expectedUser = $userIdentityManager->getUser(); $expectedUser = $userIdentityManager->getUser();
$this->assertEquals(SystemSlugType::GUEST_USER, $expectedUser->getSource()->getSlug()); $this->assertEquals(GuestUserFixtureSource::getSlug(), $expectedUser->getSource()->getSlug());
} }
public function testUser(): void public function testUser(): void

View File

@ -6,8 +6,8 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Infinito\Repository\Source\SourceRepositoryInterface; use Infinito\Repository\Source\SourceRepositoryInterface;
use Infinito\Entity\Source\AbstractSource; use Infinito\Entity\Source\AbstractSource;
use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface; use Infinito\Domain\RequestManagement\Entity\RequestedEntityInterface;
use Infinito\DBAL\Types\SystemSlugType;
use Infinito\Entity\Source\SourceInterface; use Infinito\Entity\Source\SourceInterface;
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
/** /**
* @author kevinfrantz * @author kevinfrantz
@ -32,7 +32,7 @@ class SourceRepositoryTest extends KernelTestCase
{ {
$requestedSource = $this->createMock(RequestedEntityInterface::class); $requestedSource = $this->createMock(RequestedEntityInterface::class);
$requestedSource->method('hasSlug')->willReturn(true); $requestedSource->method('hasSlug')->willReturn(true);
$requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); $requestedSource->method('getSlug')->willReturn(ImpressumFixtureSource::getSlug());
$imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource); $imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource);
$this->assertInstanceOf(SourceInterface::class, $imprint); $this->assertInstanceOf(SourceInterface::class, $imprint);
$requestedSource2 = $this->createMock(RequestedEntityInterface::class); $requestedSource2 = $this->createMock(RequestedEntityInterface::class);
@ -44,7 +44,7 @@ class SourceRepositoryTest extends KernelTestCase
public function testLoadBySlug(): void public function testLoadBySlug(): void
{ {
$imprint = $this->sourceRepository->findOneBySlug(SystemSlugType::IMPRINT); $imprint = $this->sourceRepository->findOneBySlug(ImpressumFixtureSource::getSlug());
$this->assertInstanceOf(SourceInterface::class, $imprint); $this->assertInstanceOf(SourceInterface::class, $imprint);
} }
} }