]>
Commit | Line | Data |
---|---|---|
fcb1fba5 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\ApiBundle\Tests; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
6 | use Symfony\Component\BrowserKit\Cookie; | |
7 | ||
8a493541 | 8 | abstract class WallabagApiTestCase extends WebTestCase |
fcb1fba5 NL |
9 | { |
10 | /** | |
11 | * @var Client | |
12 | */ | |
13 | protected $client = null; | |
14 | ||
4059a061 JB |
15 | /** |
16 | * @var \FOS\UserBundle\Model\UserInterface | |
17 | */ | |
18 | protected $user; | |
19 | ||
fcb1fba5 NL |
20 | public function setUp() |
21 | { | |
22 | $this->client = $this->createAuthorizedClient(); | |
23 | } | |
24 | ||
25 | /** | |
26 | * @return Client | |
27 | */ | |
28 | protected function createAuthorizedClient() | |
29 | { | |
30 | $client = static::createClient(); | |
31 | $container = $client->getContainer(); | |
32 | ||
fcb1fba5 NL |
33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
34 | $userManager = $container->get('fos_user.user_manager'); | |
35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | |
36 | $loginManager = $container->get('fos_user.security.login_manager'); | |
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | |
38 | ||
4094ea47 | 39 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
4059a061 | 40 | $loginManager->loginUser($firewallName, $this->user); |
fcb1fba5 NL |
41 | |
42 | // save the login token into the session and put it in a cookie | |
18f8f32f | 43 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); |
fcb1fba5 | 44 | $container->get('session')->save(); |
18f8f32f JB |
45 | |
46 | $session = $container->get('session'); | |
fcb1fba5 NL |
47 | $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); |
48 | ||
49 | return $client; | |
50 | } | |
51 | } |