Files
wallabag/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php

59 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-06-01 21:27:35 +02:00
namespace Tests\Wallabag\AnnotationBundle;
2022-08-28 16:59:43 +02:00
use FOS\UserBundle\Model\UserInterface;
2022-11-23 15:51:33 +01:00
use FOS\UserBundle\Model\UserManager;
2023-08-08 00:21:56 +01:00
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
abstract class WallabagAnnotationTestCase extends WebTestCase
{
/**
2023-08-08 00:21:56 +01:00
* @var KernelBrowser
*/
2024-01-01 19:11:01 +01:00
protected $client;
/**
2022-08-28 16:59:43 +02:00
* @var UserInterface
*/
protected $user;
2020-12-08 09:17:10 +01:00
protected function setUp(): void
{
2022-08-01 07:38:50 +01:00
parent::setUp();
$this->client = $this->createAuthorizedClient();
}
public function logInAs($username)
{
$crawler = $this->client->request('GET', '/login');
$form = $crawler->filter('button[type=submit]')->form();
$data = [
'_username' => $username,
'_password' => 'mypassword',
];
$this->client->submit($form, $data);
}
/**
2023-08-08 00:21:56 +01:00
* @return KernelBrowser
*/
protected function createAuthorizedClient()
{
$client = static::createClient();
$container = $client->getContainer();
2022-11-23 15:51:33 +01:00
/** @var UserManager $userManager */
$userManager = $container->get('fos_user.user_manager.test');
$firewallName = $container->getParameter('fos_user.firewall_name');
$this->user = $userManager->findUserBy(['username' => 'admin']);
2024-01-01 19:51:22 +01:00
$client->loginUser($this->user, $firewallName);
return $client;
}
}