]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
Jump to Symfony 3.1
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / WallabagCoreTestCase.php
CommitLineData
3b815d2d
J
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle;
3b815d2d
J
4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
3b815d2d 6
769e19dc 7abstract class WallabagCoreTestCase extends WebTestCase
3b815d2d
J
8{
9 private $client = null;
10
11 public function getClient()
12 {
13 return $this->client;
14 }
15
16 public function setUp()
17 {
d5027625
JB
18 parent::setUp();
19
3b815d2d
J
20 $this->client = static::createClient();
21 }
22
eb3bd7ef 23 public function logInAs($username)
3b815d2d
J
24 {
25 $crawler = $this->client->request('GET', '/login');
26 $form = $crawler->filter('button[type=submit]')->form();
4094ea47 27 $data = [
eb3bd7ef 28 '_username' => $username,
d9085c63 29 '_password' => 'mypassword',
4094ea47 30 ];
3b815d2d
J
31
32 $this->client->submit($form, $data);
33 }
78833672
JB
34
35 /**
36 * Return the user id of the logged in user.
37 * You should be sure that you called `logInAs` before.
38 *
39 * @return int
40 */
41 public function getLoggedInUserId()
42 {
43 $token = static::$kernel->getContainer()->get('security.token_storage')->getToken();
44
45 if (null !== $token) {
46 return $token->getUser()->getId();
47 }
48
49 throw new \RuntimeException('No logged in User.');
50 }
3b815d2d 51}