aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/WallabagApiTestCase.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/ApiBundle/WallabagApiTestCase.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/ApiBundle/WallabagApiTestCase.php')
-rw-r--r--tests/Wallabag/ApiBundle/WallabagApiTestCase.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php
new file mode 100644
index 00000000..cf9b3347
--- /dev/null
+++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php
@@ -0,0 +1,51 @@
1<?php
2
3namespace Tests\Wallabag\ApiBundle;
4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie;
7
8abstract class WallabagApiTestCase extends WebTestCase
9{
10 /**
11 * @var Client
12 */
13 protected $client = null;
14
15 /**
16 * @var \FOS\UserBundle\Model\UserInterface
17 */
18 protected $user;
19
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
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
39 $this->user = $userManager->findUserBy(['username' => 'admin']);
40 $loginManager->loginUser($firewallName, $this->user);
41
42 // save the login token into the session and put it in a cookie
43 $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken()));
44 $container->get('session')->save();
45
46 $session = $container->get('session');
47 $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));
48
49 return $client;
50 }
51}