From af897ffec78491011988881d34e608efeafd3692 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 11 Apr 2021 21:40:17 +0200 Subject: [PATCH] Fix loading bundle with disabled impersonating --- .../NucleosUserAdminExtension.php | 19 ++------------- .../NucleosUserAdminExtensionTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/DependencyInjection/NucleosUserAdminExtension.php b/src/DependencyInjection/NucleosUserAdminExtension.php index b7a2d163..4f4cc6d7 100644 --- a/src/DependencyInjection/NucleosUserAdminExtension.php +++ b/src/DependencyInjection/NucleosUserAdminExtension.php @@ -71,9 +71,9 @@ public function load(array $configs, ContainerBuilder $container): void $this->configureTranslationDomain($config, $container); $this->configureController($config, $container); - if (false !== $config['impersonating']) { - $loader->load('impersonating.php'); + $loader->load('impersonating.php'); + if (false !== $config['impersonating']) { $container->getDefinition(ImpersonateExtension::class) ->replaceArgument(1, $config['impersonating']['route']) ->replaceArgument(2, $config['impersonating']['parameters']) @@ -89,21 +89,6 @@ private function configureAvatar(array $config, ContainerBuilder $container): vo $container->setParameter('nucleos_user_admin.default_avatar', $config['avatar']['default_avatar']); } - /** - * Adds aliases for user & group managers depending on $managerType. - */ - private function aliasManagers(ContainerBuilder $container, string $managerType): void - { - $container - ->setAlias('nucleos_user_admin.user_manager', sprintf('nucleos_user_admin.%s.user_manager', $managerType)) - ->setPublic(true) - ; - $container - ->setAlias('nucleos_user_admin.group_manager', sprintf('nucleos_user_admin.%s.group_manager', $managerType)) - ->setPublic(true) - ; - } - /** * @throws RuntimeException */ diff --git a/tests/DependencyInjection/NucleosUserAdminExtensionTest.php b/tests/DependencyInjection/NucleosUserAdminExtensionTest.php index 6cd58522..a45e70bc 100644 --- a/tests/DependencyInjection/NucleosUserAdminExtensionTest.php +++ b/tests/DependencyInjection/NucleosUserAdminExtensionTest.php @@ -18,6 +18,7 @@ use Nucleos\UserAdminBundle\Admin\Entity\UserAdmin; use Nucleos\UserAdminBundle\DependencyInjection\Configuration; use Nucleos\UserAdminBundle\DependencyInjection\NucleosUserAdminExtension; +use Nucleos\UserAdminBundle\Twig\ImpersonateExtension; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -90,6 +91,29 @@ public function testTwigConfigParameterIsNotSet(): void static::assertArrayNotHasKey(0, $twigConfigurations); } + public function testLoadWithoutImpersonating(): void + { + $this->load(); + + $this->assertContainerBuilderHasService(ImpersonateExtension::class); + } + + public function testLoadWithImpersonating(): void + { + $this->load([ + 'impersonating' => [ + 'route' => 'my_route', + 'parameters' => [ + 'foo' => 'bar', + ], + ], + ]); + + $this->assertContainerBuilderHasService(ImpersonateExtension::class); + $this->assertContainerBuilderHasServiceDefinitionWithArgument(ImpersonateExtension::class, 1, 'my_route'); + $this->assertContainerBuilderHasServiceDefinitionWithArgument(ImpersonateExtension::class, 2, ['foo' => 'bar']); + } + /** * @doesNotPerformAssertions */