diff options
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php')
-rw-r--r-- | src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php b/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php deleted file mode 100644 index a9035acc..00000000 --- a/src/Wallabag/AnnotationBundle/Tests/WallabagAnnotationTestCase.php +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\AnnotationBundle\Tests; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
6 | use Symfony\Component\BrowserKit\Cookie; | ||
7 | |||
8 | abstract class WallabagAnnotationTestCase 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 | public function logInAs($username) | ||
26 | { | ||
27 | $crawler = $this->client->request('GET', '/login'); | ||
28 | $form = $crawler->filter('button[type=submit]')->form(); | ||
29 | $data = [ | ||
30 | '_username' => $username, | ||
31 | '_password' => 'mypassword', | ||
32 | ]; | ||
33 | |||
34 | $this->client->submit($form, $data); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * @return Client | ||
39 | */ | ||
40 | protected function createAuthorizedClient() | ||
41 | { | ||
42 | $client = static::createClient(); | ||
43 | $container = $client->getContainer(); | ||
44 | |||
45 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | ||
46 | $userManager = $container->get('fos_user.user_manager'); | ||
47 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | ||
48 | $loginManager = $container->get('fos_user.security.login_manager'); | ||
49 | $firewallName = $container->getParameter('fos_user.firewall_name'); | ||
50 | |||
51 | $this->user = $userManager->findUserBy(['username' => 'admin']); | ||
52 | $loginManager->loginUser($firewallName, $this->user); | ||
53 | |||
54 | // save the login token into the session and put it in a cookie | ||
55 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); | ||
56 | $container->get('session')->save(); | ||
57 | |||
58 | $session = $container->get('session'); | ||
59 | $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); | ||
60 | |||
61 | return $client; | ||
62 | } | ||
63 | } | ||