public function setUp()
 {
     $this->client = static::createClient();
     $this->client->followRedirects();
     $this->container = $this->client->getContainer();
     $this->loadFixtures($this->getFixtures());
 }
 protected function setUp()
 {
     $this->client = static::createClient();
     $this->client->followRedirects(true);
     $this->crawler = $this->client->request('GET', self::REGISTRATION_URL);
     $this->form = $this->crawler->selectButton(self::SUBMIT_BUTTON)->form();
 }
 /**
  * @dataProvider provideAnonymousUrls
  * @coversNothing
  *
  * @param string $url
  * @param string $expectedText
  */
 public function testAnonymousUrl($url, $expectedText)
 {
     self::$client = static::createClient();
     self::$client->followRedirects();
     $crawler = self::$client->request('GET', $url);
     $this->assertEquals(200, self::$client->getResponse()->getStatusCode(), 'Ensure status is 200');
     $this->assertEquals(1, $crawler->filter('html:contains("' . $expectedText . '")')->count(), "The text '{$expectedText}' should be present in the HTML page");
 }
 protected function setUp()
 {
     parent::setUp();
     $this->client = static::createClient();
     $this->client->followRedirects();
     $this->kern = $this->client->getKernel();
     $this->container = $this->client->getContainer();
     $this->em = $this->container->get('doctrine.orm.entity_manager');
 }
 /**
  * Use this function to connect to user in the application using login form
  * MORE SLOW, Use connectUser function above instead
  *
  * @param $username
  * @param $password
  * @return Client
  */
 protected function loginUsingFormUser($username, $password)
 {
     $this->client = static::createClient();
     $this->crawler = $this->client->request('GET', '/login');
     $credentials = array('_username' => $username, '_password' => $password);
     $form = $this->crawler->selectButton('_submit')->form($credentials);
     $this->client->submit($form);
     $this->client->followRedirects();
     return $this->client;
 }
 /**
  * @dataProvider provideLoginData
  */
 public function testLogin(Client $client, $securedUrl, $login, $expectedMessage)
 {
     // client follow redirects
     $client->followRedirects();
     // go to secured page -> got login required
     $crawler = $client->request('GET', $securedUrl);
     $this->assertEquals(TrustedSsoController::LOGIN_REQUIRED_MESSAGE, $crawler->filter('#message')->text());
     // click link -> got login form
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals('login', $crawler->filter('form')->attr('id'));
     // fill form & submit -> got expected message
     $form = $crawler->filter('input[type=submit]')->form();
     $crawler = $client->submit($form, array('login[username]' => $login, 'login[password]' => $login));
     $this->assertEquals($expectedMessage, $crawler->filter('#message')->text());
     if (!$login === self::LOGIN_INVALID) {
         // check validation attributes
         $attrs = static::$kernel->getContainer()->get('security.context')->getToken()->getValidationAttributes();
         $this->assertEquals(array('attr1' => 'val1', 'attr2' => 'val2'), $attrs);
     }
     // logout -> got logout redirect
     $crawler = $client->request('GET', '/secured/logout');
     $this->assertEquals(TrustedSsoController::LOGOUT_REDIRECT_MESSAGE, $crawler->filter('#message')->text());
     // click link -> got logout done
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals(ServerController::LOGOUT_MESSAGE, $crawler->filter('#message')->text());
     // click link -> go to homepage
     $crawler = $client->click($crawler->filter('#url')->link());
     $this->assertEquals(TestController::HOME_MESSAGE, $crawler->filter('#message')->text());
 }
 /**
  * External
  */
 public function testExternalLink()
 {
     $this->createConfig();
     $this->createAccount();
     $referrerUrl = self::$client->getContainer()->get('router')->generate('keboola_google_analytics_external_auth_finish', array(), true);
     self::$client->followRedirects();
     self::$client->request('POST', '/ex-google-analytics/external-link', array(), array(), array(), json_encode(array('account' => 'test', 'referrer' => $referrerUrl)));
     $responseJson = self::$client->getResponse()->getContent();
     $response = json_decode($responseJson, true);
     $this->assertArrayHasKey('link', $response);
     $this->assertNotEmpty($response['link']);
 }
 public function testDeletePost()
 {
     $data = array('_csrf_token' => 'testtoken', 'content' => 'Test content', 'title' => 'test title');
     $this->client->getCookieJar()->set(new Cookie('cookie_csrf', 'testtoken'));
     $this->client->followRedirects(true);
     /** @var Crawler $crawler */
     $crawler = $this->jsonRequest('PUT', '/api/posts/1', $data);
     $this->assertJsonResponse($this->client->getResponse(), 201);
     $this->assertEmpty($this->client->getResponse()->getContent());
     /** @var Crawler $crawler */
     $crawler = $this->jsonRequest('DELETE', '/api/posts/1', $data);
     $this->assertEquals(204, $this->client->getResponse()->getStatusCode());
 }
Example #9
0
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     if (isset($this->client)) {
         $this->client = null;
         unset($this->client);
     }
     $this->client = $this->createClient();
     //XXX: Follow this bug : https://github.com/symfony/symfony/issues/1726
     //$this->client->insulate();
     //Redirections is forced by default
     $this->client->followRedirects();
     //Session is invalidated
     $session = $this->client->getContainer()->get('session');
     if (isset($session)) {
         $session->invalidate();
     }
     $this->em = $this->client->getContainer()->get('doctrine')->getEntityManager();
     $this->t = $this->client->getContainer()->get('translator');
     $this->logger = $this->client->getContainer()->get('logger');
     $this->router = $this->client->getContainer()->get('router');
     $this->logger->info('######## Starting ' . $this->getName() . ' at ' . time() . ' ########');
 }
 /**
  * @param \Symfony\Bundle\FrameworkBundle\Client $client
  * @param bool                                   $asAdmin
  *
  * @return User
  */
 public function login($client, $asAdmin = false)
 {
     $testUser = $asAdmin ? $this->createLoginAdminUser() : $this->createLoginUser();
     $username = $testUser->getUsername();
     $passwort = $testUser->getPlainPassword();
     $this->saveInDb([$testUser]);
     $crawler = $client->request('GET', '/login');
     $client->followRedirects();
     $loginForm = $crawler->selectButton('_submit')->form();
     $loginForm['_username'] = $username;
     $loginForm['_password'] = $passwort;
     $crawler = $client->submit($loginForm);
     $this->assertFalse((bool) $crawler->filter('.form-signin')->count(), "Can't Login User.");
     return $testUser;
 }
 public function setUp()
 {
     parent::setUp();
     $this->client = static::createClient();
     $this->client->followRedirects();
 }
 /**
  * Sets whether to automatically follow redirects or not.
  *
  * @param bool $followRedirect Whether to follow redirects
  *
  * @api
  */
 public function followRedirects($followRedirect = true)
 {
     $this->subject->followRedirects($followRedirect);
 }