Example #1
0
 /**
  * @return Crawler
  * @throws \Exception
  */
 protected static function loginAsUser()
 {
     $uri = self::$container->get('router')->generate('login_route');
     $crawler = self::$client->request('GET', $uri);
     $form = $crawler->selectButton('login_btn')->form(['_username' => 'test', '_password' => '12345678']);
     self::$client->submit($form);
     self::assertTrue(self::$client->getResponse()->isRedirection());
     return self::$client->followRedirect();
 }
 /**
  * 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;
 }
 public function testRegisterSuccess()
 {
     $this->form[self::USERNAME_FIELD] = self::USERNAME;
     $this->form[self::EMAIL_FIELD] = self::EMAIL;
     $this->form[self::PASSWORD_FIELD] = self::PASSWORD;
     $this->form[self::REPEAT_PASSWORD_FIELD] = self::PASSWORD;
     $this->crawler = $this->client->submit($this->form);
     $this->assertEmpty($this->crawler->filter(self::ERROR_SELECTOR));
     $this->assertNotEquals(self::REGISTRATION_URL, $this->client->getRequest()->getRequestUri());
 }
 private function addBattery($type, $count, $name = null)
 {
     $crawler = $this->client->request('GET', '/add');
     $buttonCrawlerNode = $crawler->selectButton('Save');
     $form = $buttonCrawlerNode->form();
     $form['battery[type]'] = $type;
     $form['battery[count]'] = $count;
     $form['battery[name]'] = $name;
     $this->client->submit($form);
 }
Example #5
0
 public function doLogin($username)
 {
     /** @var Crawler */
     $crawler = $this->client->request('GET', '/login');
     /** @var Response */
     $response = $this->client->getResponse();
     /** @var Form */
     $form = $crawler->selectButton('Login')->form();
     $form['_username'] = $username;
     $form['_password'] = '******';
     $crawler = $this->client->submit($form);
 }
 /**
  * Test form login with invalid user
  */
 public function testLoginWithInvalidUser()
 {
     $userName = '******';
     $password = '******';
     $crawler = $this->client->request('GET', '/login');
     $form = $crawler->selectButton('Log in')->form();
     $form['_username'] = $userName;
     $form['_password'] = $password;
     $this->client->submit($form);
     $this->assertEquals(302, $this->client->getResponse()->getStatusCode());
     $token = $this->client->getContainer()->get('security.token_storage')->getToken();
     $this->assertNull($token);
 }
Example #7
0
 public function testAdd()
 {
     $crawler = $this->client->request('GET', '/member/add');
     $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
     $this->assertEquals(1, $crawler->filter('div.app_member_add')->count());
     $this->assertEquals(1, $crawler->selectButton('add')->count());
     $button = $crawler->selectButton('add')->first();
     $form = $button->form(array('member[firstname]' => 'John', 'member[lastname]' => 'Doe', 'member[gender]' => 'm', 'member[birthday]' => '11/04/1980', 'member[birthplace]' => 'New-York City', 'member[address]' => 'Main street', 'member[zip]' => '01234', 'member[city]' => 'Washington D.C.'));
     $form['member[photo]']->upload(__DIR__ . '/../../photo.jpg');
     $this->client->submit($form);
     $this->assertTrue($this->client->getResponse()->isRedirect());
     $crawler = $this->client->followRedirect();
     $this->assertEquals(1, $crawler->filter('div.flash.success')->count());
 }
 /**
  * test que les modifications d'un profil fonctionne
  */
 public function testEditProfile()
 {
     $crawler = $this->client->request('GET', '/profil');
     $form = $crawler->selectButton('Envoyer')->form();
     $form['application_sonata_user_profile[lastname]'] = 'Aaa';
     $form['application_sonata_user_profile[firstname]'] = 'Aaa';
     $form['application_sonata_user_profile[adresse]'] = '4 rue du bois';
     $form['application_sonata_user_profile[codePostal]'] = '28240';
     $form['application_sonata_user_profile[phone]'] = '0768298272';
     $form['application_sonata_user_profile[telephoneSecondaire]'] = '0768298272';
     $form['application_sonata_user_profile[caf]'] = '1234567';
     $form['application_sonata_user_profile[numeroIban]'] = '1234567891011121314151617181920AZERTYU';
     $crawler = $this->client->submit($form);
     $this->assertNotNull($crawler);
 }
 /**
  * @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());
 }
 public function testValidationEmail()
 {
     $crawler = $this->client->request('GET', '/contact');
     $form = $crawler->filter('form')->form();
     // L'email est vide
     $this->client->submit($form);
     $this->assertTrue($this->client->getResponse()->isClientError());
 }
 public function testRedirectRouteCreate()
 {
     $crawler = $this->client->request('GET', '/admin/cmf/routing/redirectroute/create');
     $res = $this->client->getResponse();
     $this->assertEquals(200, $res->getStatusCode());
     $this->assertFrontendLinkNotPresent($crawler);
     $button = $crawler->selectButton('Create');
     $form = $button->form();
     $node = $form->getFormNode();
     $actionUrl = $node->getAttribute('action');
     $uniqId = substr(strchr($actionUrl, '='), 1);
     $form[$uniqId . '[parent]'] = '/test/routing';
     $form[$uniqId . '[name]'] = 'foo-test';
     $this->client->submit($form);
     $res = $this->client->getResponse();
     // If we have a 302 redirect, then all is well
     $this->assertEquals(302, $res->getStatusCode());
 }
 public function testCreationPageEleveur_NomInvalide()
 {
     // connexion avec un nouvel user
     $this->testUtils->createUser();
     $pageEleveurForm = $this->client->request('GET', '/')->filter('form[name="creation-page-eleveur"]')->form();
     $pageEleveurForm['creation-page-eleveur[nom]'] = '--';
     $this->client->submit($pageEleveurForm);
     $this->assertEquals(Response::HTTP_NOT_ACCEPTABLE, $this->client->getResponse()->getStatusCode());
 }
 /**
  * Make defaults deletion assertions.
  *
  * @param $url string the deletion url
  */
 protected function makeDeleteAssertions($url)
 {
     $crawler = $this->client->request('GET', $url);
     $res = $this->client->getResponse();
     $this->assertResponseSuccess($res);
     $button = $crawler->selectButton('Yes, delete');
     $form = $button->form();
     $this->client->submit($form);
     $res = $this->client->getResponse();
     // If we have a 302 redirect, then all is well
     $this->assertEquals(302, $res->getStatusCode(), $res->getContent());
 }
 private function startRegistration(\Symfony\Bundle\FrameworkBundle\Client $client, array $fields, $reset = true)
 {
     if ($reset) {
         $this->resetDatabase();
     }
     $crawler = $client->request('GET', '/');
     $buttonNode = $crawler->selectButton('Absenden');
     $form = $buttonNode->form();
     $form->disableValidation();
     $client->enableProfiler();
     $crawler = $client->submit($form, $fields);
     return $crawler;
 }
 /**
  * @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;
 }
 /**
  * When user is logged in, and he selects profile, then settings container must receive that choice.
  */
 public function testSettingsSelected()
 {
     // Set authentication cookie.
     CookieTestHelper::setAuthenticationCookie($this->client);
     // Retrieve content.
     $crawler = $this->client->request('GET', '/settings/settings');
     // Submit domain selection.
     $buttonNode = $crawler->selectButton('settings_submit');
     $form = $buttonNode->form();
     /** @noinspection PhpUndefinedMethodInspection */
     $form['settings[ongr_settings_profile_profile_foo-2e-com]']->tick();
     $this->client->submit($form);
     // Load any url and check that user selected domains are loaded.
     $this->client->request('GET', '/settings/setting/name0/edit');
     $settingsContainer = $this->client->getContainer()->get('ongr_settings.settings_container');
     $selectedDomains = $settingsContainer->getProfiles();
     $this->assertEquals(['default', 'profile_foo.com'], $selectedDomains);
 }
 /**
  * Submits a form.
  *
  * @param Form  $form   A Form instance
  * @param array $values An array of form field values
  *
  * @return Crawler
  *
  * @api
  */
 public function submit(Form $form, array $values = [])
 {
     return $this->subject->submit($form, $values);
 }
 /**
  * @param \Symfony\Component\DomCrawler\Crawler $crawler
  * @param \Symfony\Bundle\FrameworkBundle\Client $client
  *
  * @return mixed
  */
 private function runTroughStep5($crawler, $client)
 {
     $form = $crawler->selectButton('Finish installation')->form();
     $client->submit($form, array('install_login[email]' => '*****@*****.**', 'install_login[password][first]' => 'password', 'install_login[password][second]' => 'password'));
     $crawler = $client->followRedirect();
     // we should be redirected to step 6
     self::assertEquals(200, $client->getResponse()->getStatusCode());
     self::assertStringEndsWith('/install/6', $client->getHistory()->current()->getUri());
     self::assertGreaterThan(0, $crawler->filter('h2:contains("Installation complete")')->count());
     return $crawler;
 }
 /**
  * Moves forward to the summary page
  *
  * @param \Symfony\Bundle\FrameworkBundle\Client $client HTTP test client
  * @return \Symfony\Component\DomCrawler\Crawler Crawler HTTP crawler
  */
 protected function _goToSummary($client)
 {
     $crawler = $client->request('GET', '/unittest/de/EUR/list');
     $link = $crawler->filter('.catalog-list-items .product a:contains("Unittest: Bundle")')->link();
     $crawler = $client->click($link);
     $form = $crawler->filter('.catalog-detail .addbasket .btn-action')->form();
     $crawler = $client->submit($form);
     $link = $crawler->filter('.basket-standard .btn-action')->link();
     $crawler = $client->click($link);
     $form = $crawler->filter('.checkout-standard form')->form();
     $form['ca_billingoption']->select($crawler->filter('.checkout-standard-address .item-address input')->attr('value'));
     $crawler = $client->submit($form);
     $form = $crawler->filter('.checkout-standard form')->form();
     $form['c_deliveryoption']->select($crawler->filter('.checkout-standard-delivery .item-service input')->attr('value'));
     $crawler = $client->submit($form);
     $form = $crawler->filter('.checkout-standard form')->form();
     $form['c_paymentoption']->select($crawler->filter('.checkout-standard-payment .item-service input')->attr('value'));
     $crawler = $client->submit($form);
     return $crawler;
 }
Example #20
0
 /**
  * Submits the form and mimics the GET parameters, since they aren't added
  * by default in the functional tests
  *
  * @param  Client $client
  * @param  Form   $form
  * @param  array  $data
  */
 protected function submitForm(Client $client, Form $form, array $data = array())
 {
     // Get parameters should be set manually. Symfony uses the request object,
     // but spoon still checks the $_GET and $_POST parameters
     foreach ($data as $key => $value) {
         $_GET[$key] = $value;
         $_POST[$key] = $value;
     }
     $client->submit($form);
     foreach ($data as $key => $value) {
         unset($_GET[$key]);
         unset($_POST[$key]);
     }
 }