3 namespace Tests\Wallabag\AnnotationBundle
;
5 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
6 use Symfony\Component\BrowserKit\Cookie
;
8 abstract class WallabagAnnotationTestCase
extends WebTestCase
11 * @var \Symfony\Bundle\FrameworkBundle\Client
13 protected $client = null;
16 * @var \FOS\UserBundle\Model\UserInterface
20 public function setUp()
22 $this->client
= $this->createAuthorizedClient();
25 public function logInAs($username)
27 $crawler = $this->client
->request('GET', '/login');
28 $form = $crawler->filter('button[type=submit]')->form();
30 '_username' => $username,
31 '_password' => 'mypassword',
34 $this->client
->submit($form, $data);
38 * @return \Symfony\Bundle\FrameworkBundle\Client
40 protected function createAuthorizedClient()
42 $client = static::createClient();
43 $container = $client->getContainer();
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');
51 $this->user
= $userManager->findUserBy(['username' => 'admin']);
52 $loginManager->logInUser($firewallName, $this->user
);
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();
58 $session = $container->get('session');
59 $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));