aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-06-24 11:55:45 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-06-24 11:55:47 +0200
commitfdc90ceb172bb7b237e34a1a01f53018c09f514b (patch)
tree6b2a4ad27428497713eef68ce57d4b58f18507cc /tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
parent2bc9cad78ed43eaadfc8844c0b55700e7045cbd7 (diff)
downloadwallabag-fdc90ceb172bb7b237e34a1a01f53018c09f514b.tar.gz
wallabag-fdc90ceb172bb7b237e34a1a01f53018c09f514b.tar.zst
wallabag-fdc90ceb172bb7b237e34a1a01f53018c09f514b.zip
Change the way to login user in tests
Instead of using a HTTP request we just login user like FOSUser does. It allows us to mock service in container for functional tests. Also, fix a bad config name in fos_user for firewall And finally, add functional test to PocketImport
Diffstat (limited to 'tests/Wallabag/CoreBundle/WallabagCoreTestCase.php')
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index c69e8330..c0055888 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle; 3namespace Tests\Wallabag\CoreBundle;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie;
6 7
7abstract class WallabagCoreTestCase extends WebTestCase 8abstract class WallabagCoreTestCase extends WebTestCase
8{ 9{
@@ -20,8 +21,39 @@ abstract class WallabagCoreTestCase extends WebTestCase
20 $this->client = static::createClient(); 21 $this->client = static::createClient();
21 } 22 }
22 23
24 /**
25 * Login a user without making a HTTP request.
26 * If we make a HTTP request we lose ability to mock service in the container.
27 *
28 * @param string $username User to log in
29 */
23 public function logInAs($username) 30 public function logInAs($username)
24 { 31 {
32 $container = $this->client->getContainer();
33 $session = $container->get('session');
34
35 $userManager = $container->get('fos_user.user_manager');
36 $loginManager = $container->get('fos_user.security.login_manager');
37 $firewallName = $container->getParameter('fos_user.firewall_name');
38
39 $user = $userManager->findUserBy(array('username' => $username));
40 $loginManager->loginUser($firewallName, $user);
41
42 $session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken()));
43 $session->save();
44
45 $cookie = new Cookie($session->getName(), $session->getId());
46 $this->client->getCookieJar()->set($cookie);
47 }
48
49 /**
50 * Instead of `logInAs` this method use a HTTP request to log in the user.
51 * Could be better for some tests.
52 *
53 * @param string $username User to log in
54 */
55 public function logInAsUsingHttp($username)
56 {
25 $crawler = $this->client->request('GET', '/login'); 57 $crawler = $this->client->request('GET', '/login');
26 $form = $crawler->filter('button[type=submit]')->form(); 58 $form = $crawler->filter('button[type=submit]')->form();
27 $data = [ 59 $data = [