diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
---|---|---|
committer | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2015-10-06 09:19:06 +0200 |
commit | 16dabc326311f084d671be188c7941bbb3c341c9 (patch) | |
tree | 3210a7688ea2bfa1bff5fd0422b52adf570edcdc /src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | |
parent | fdef5f460524215d806e244e5546865f4b8e01df (diff) | |
parent | 8263e71192989dc0fd28a41ac22f9c5b32eb11c4 (diff) | |
download | wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.gz wallabag-16dabc326311f084d671be188c7941bbb3c341c9.tar.zst wallabag-16dabc326311f084d671be188c7941bbb3c341c9.zip |
Merge pull request #1436 from wallabag/v2-register
Public registration & oAuth2 \o/
Diffstat (limited to 'src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php new file mode 100644 index 00000000..119889b3 --- /dev/null +++ b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | |||
@@ -0,0 +1,46 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ApiBundle\Tests; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
6 | use Symfony\Component\BrowserKit\Cookie; | ||
7 | |||
8 | abstract class AbstractControllerTest extends WebTestCase | ||
9 | { | ||
10 | /** | ||
11 | * @var Client | ||
12 | */ | ||
13 | protected $client = null; | ||
14 | |||
15 | public function setUp() | ||
16 | { | ||
17 | $this->client = $this->createAuthorizedClient(); | ||
18 | } | ||
19 | |||
20 | /** | ||
21 | * @return Client | ||
22 | */ | ||
23 | protected function createAuthorizedClient() | ||
24 | { | ||
25 | $client = static::createClient(); | ||
26 | $container = $client->getContainer(); | ||
27 | |||
28 | $session = $container->get('session'); | ||
29 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | ||
30 | $userManager = $container->get('fos_user.user_manager'); | ||
31 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | ||
32 | $loginManager = $container->get('fos_user.security.login_manager'); | ||
33 | $firewallName = $container->getParameter('fos_user.firewall_name'); | ||
34 | |||
35 | $user = $userManager->findUserBy(array('username' => 'admin')); | ||
36 | $loginManager->loginUser($firewallName, $user); | ||
37 | |||
38 | // save the login token into the session and put it in a cookie | ||
39 | $container->get('session')->set('_security_'.$firewallName, | ||
40 | serialize($container->get('security.context')->getToken())); | ||
41 | $container->get('session')->save(); | ||
42 | $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); | ||
43 | |||
44 | return $client; | ||
45 | } | ||
46 | } | ||