aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-06-23 11:47:46 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-06-23 11:47:46 +0200
commitf49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4 (patch)
tree156b1a29cfbe1962e68d409c3dea5a3911a34e9c /tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
parent49e2854d5c15bbce3f24f91da34450e8f209295b (diff)
parentfb5c17a9ab5e10b1de9caa50e73638fdae19cb78 (diff)
downloadwallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.gz
wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.tar.zst
wallabag-f49d9ca383c9f8a1bc426cfabf6b1cea53ea26b4.zip
Merge branch 'master' into 2.1
Diffstat (limited to 'tests/Wallabag/CoreBundle/WallabagCoreTestCase.php')
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
new file mode 100644
index 00000000..c69e8330
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -0,0 +1,51 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle;
4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7abstract class WallabagCoreTestCase extends WebTestCase
8{
9 private $client = null;
10
11 public function getClient()
12 {
13 return $this->client;
14 }
15
16 public function setUp()
17 {
18 parent::setUp();
19
20 $this->client = static::createClient();
21 }
22
23 public function logInAs($username)
24 {
25 $crawler = $this->client->request('GET', '/login');
26 $form = $crawler->filter('button[type=submit]')->form();
27 $data = [
28 '_username' => $username,
29 '_password' => 'mypassword',
30 ];
31
32 $this->client->submit($form, $data);
33 }
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 }
51}