aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/WallabagApiTestCase.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-06-23 09:18:18 +0200
committerGitHub <noreply@github.com>2016-06-23 09:18:18 +0200
commitd37bb05c881bfdbeb1144b327edd4dcc2cbb163f (patch)
tree1b90f7e733a83af4741a8cb7f49edf3e303f8677 /tests/Wallabag/ApiBundle/WallabagApiTestCase.php
parent891a026e31ad54ca90b70f6026f23260cfadb7fd (diff)
parent99451fe4b76051d61922a6beb7ee9e79cc6e7893 (diff)
downloadwallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.gz
wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.tar.zst
wallabag-d37bb05c881bfdbeb1144b327edd4dcc2cbb163f.zip
Merge pull request #2132 from wallabag/sf3.1
Jump to Symfony 3.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}