Refactor authentication system (#2602)
Make auth configuration available via UI, remove FOSUserBundle and SAML-Bundle dependency
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\DataFixtures\UserFixtures;
|
||||
use App\Entity\Configuration;
|
||||
use App\Entity\User;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Tests\KernelTestTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
@@ -33,6 +35,43 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Using a special container, to access private services as well.
|
||||
*
|
||||
* @param string $service
|
||||
* @return object|null
|
||||
* @see https://symfony.com/blog/new-in-symfony-4-1-simpler-service-testing
|
||||
*/
|
||||
protected function getPrivateService(string $service)
|
||||
{
|
||||
return self::$container->get($service);
|
||||
}
|
||||
|
||||
protected function loadUserFromDatabase(string $username)
|
||||
{
|
||||
$container = self::$kernel->getContainer();
|
||||
/** @var UserRepository $userRepository */
|
||||
$userRepository = $container->get('doctrine')->getRepository(User::class);
|
||||
$user = $userRepository->loadUserByUsername($username);
|
||||
self::assertInstanceOf(User::class, $user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function setSystemConfiguration(string $name, $value): void
|
||||
{
|
||||
$repository = static::$kernel->getContainer()->get(ConfigurationRepository::class);
|
||||
|
||||
$entity = $repository->findOneBy(['name' => $name]);
|
||||
if ($entity === null) {
|
||||
$entity = new Configuration();
|
||||
$entity->setName($name);
|
||||
}
|
||||
$entity->setValue($value);
|
||||
$repository->saveConfiguration($entity);
|
||||
$this->clearConfigCache();
|
||||
}
|
||||
|
||||
protected function clearConfigCache()
|
||||
{
|
||||
/** @var ConfigurationRepository $repository */
|
||||
|
||||
Reference in New Issue
Block a user