diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-07-20 12:02:02 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-07-20 12:02:02 +0200 |
commit | 0faeabefa7faedb3a6a3675a5e49e947554adae9 (patch) | |
tree | e51ae7db64408b159b2dfa13bfa9e01530223dc9 /tests/Wallabag/CoreBundle | |
parent | 2bb138ef6df2d1a608b42907185b274fb87f4513 (diff) | |
parent | 317fc6e684356b645ea1327c2631c7d5fc193ddd (diff) | |
download | wallabag-0faeabefa7faedb3a6a3675a5e49e947554adae9.tar.gz wallabag-0faeabefa7faedb3a6a3675a5e49e947554adae9.tar.zst wallabag-0faeabefa7faedb3a6a3675a5e49e947554adae9.zip |
Merge remote-tracking branch 'origin/master' into 2.1
Diffstat (limited to 'tests/Wallabag/CoreBundle')
3 files changed, 39 insertions, 1 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index f503ff4b..03355f5a 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php | |||
@@ -36,7 +36,7 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
36 | $em->persist($user); | 36 | $em->persist($user); |
37 | $em->flush(); | 37 | $em->flush(); |
38 | 38 | ||
39 | $this->logInAs('admin'); | 39 | $this->logInAsUsingHttp('admin'); |
40 | $crawler = $client->request('GET', '/config'); | 40 | $crawler = $client->request('GET', '/config'); |
41 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); | 41 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); |
42 | 42 | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index a019d36c..58450e5f 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -39,6 +39,12 @@ class TagControllerTest extends WallabagCoreTestCase | |||
39 | $client->submit($form, $data); | 39 | $client->submit($form, $data); |
40 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 40 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
41 | 41 | ||
42 | // be sure to reload the entry | ||
43 | $entry = $client->getContainer() | ||
44 | ->get('doctrine.orm.entity_manager') | ||
45 | ->getRepository('WallabagCoreBundle:Entry') | ||
46 | ->findOneByUsernameAndNotArchived('admin'); | ||
47 | |||
42 | $this->assertEquals(1, count($entry->getTags())); | 48 | $this->assertEquals(1, count($entry->getTags())); |
43 | 49 | ||
44 | # tag already exists and already assigned | 50 | # tag already exists and already assigned |
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 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle; | 3 | namespace Tests\Wallabag\CoreBundle; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6 | use Symfony\Component\BrowserKit\Cookie; | ||
6 | 7 | ||
7 | abstract class WallabagCoreTestCase extends WebTestCase | 8 | abstract 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 = [ |