123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- <?php
- namespace Behat\Mink\Tests\Driver\Form;
- use Behat\Mink\Tests\Driver\TestCase;
- class GeneralTest extends TestCase
- {
- // test multiple submit buttons
- public function testIssue212()
- {
- $session = $this->getSession();
- $session->visit($this->pathTo('/issue212.html'));
- $field = $this->findById('poney-button');
- $this->assertEquals('poney', $field->getValue());
- }
- public function testBasicForm()
- {
- $this->getSession()->visit($this->pathTo('/basic_form.html'));
- $webAssert = $this->getAssertSession();
- $page = $this->getSession()->getPage();
- $this->assertEquals('Basic Form Page', $webAssert->elementExists('css', 'h1')->getText());
- $firstname = $webAssert->fieldExists('first_name');
- $lastname = $webAssert->fieldExists('lastn');
- $this->assertEquals('Firstname', $firstname->getValue());
- $this->assertEquals('Lastname', $lastname->getValue());
- $firstname->setValue('Konstantin');
- $page->fillField('last_name', 'Kudryashov');
- $this->assertEquals('Konstantin', $firstname->getValue());
- $this->assertEquals('Kudryashov', $lastname->getValue());
- $page->findButton('Reset')->click();
- $this->assertEquals('Firstname', $firstname->getValue());
- $this->assertEquals('Lastname', $lastname->getValue());
- $firstname->setValue('Konstantin');
- $page->fillField('last_name', 'Kudryashov');
- $page->findButton('Save')->click();
- if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
- $this->assertEquals('Anket for Konstantin', $webAssert->elementExists('css', 'h1')->getText());
- $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
- $this->assertEquals('Lastname: Kudryashov', $webAssert->elementExists('css', '#last')->getText());
- }
- }
- /**
- * @dataProvider formSubmitWaysDataProvider
- */
- public function testFormSubmitWays($submitVia)
- {
- $session = $this->getSession();
- $session->visit($this->pathTo('/basic_form.html'));
- $page = $session->getPage();
- $webAssert = $this->getAssertSession();
- $firstname = $webAssert->fieldExists('first_name');
- $firstname->setValue('Konstantin');
- $page->findButton($submitVia)->click();
- if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
- $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
- } else {
- $this->fail('Form was never submitted');
- }
- }
- public function formSubmitWaysDataProvider()
- {
- return array(
- array('Save'),
- array('input-type-image'),
- array('button-without-type'),
- array('button-type-submit'),
- );
- }
- public function testFormSubmit()
- {
- $session = $this->getSession();
- $session->visit($this->pathTo('/basic_form.html'));
- $webAssert = $this->getAssertSession();
- $webAssert->fieldExists('first_name')->setValue('Konstantin');
- $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
- if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
- $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
- };
- }
- public function testFormSubmitWithoutButton()
- {
- $session = $this->getSession();
- $session->visit($this->pathTo('/form_without_button.html'));
- $webAssert = $this->getAssertSession();
- $webAssert->fieldExists('first_name')->setValue('Konstantin');
- $webAssert->elementExists('xpath', 'descendant-or-self::form[1]')->submit();
- if ($this->safePageWait(5000, 'document.getElementById("first") !== null')) {
- $this->assertEquals('Firstname: Konstantin', $webAssert->elementExists('css', '#first')->getText());
- };
- }
- public function testBasicGetForm()
- {
- $this->getSession()->visit($this->pathTo('/basic_get_form.php'));
- $webAssert = $this->getAssertSession();
- $page = $this->getSession()->getPage();
- $this->assertEquals('Basic Get Form Page', $webAssert->elementExists('css', 'h1')->getText());
- $search = $webAssert->fieldExists('q');
- $search->setValue('some#query');
- $page->pressButton('Find');
- $div = $webAssert->elementExists('css', 'div');
- $this->assertEquals('some#query', $div->getText());
- }
- public function testAdvancedForm()
- {
- $this->getSession()->visit($this->pathTo('/advanced_form.html'));
- $page = $this->getSession()->getPage();
- $page->fillField('first_name', 'ever');
- $page->fillField('last_name', 'zet');
- $page->pressButton('Register');
- $this->assertContains('no file', $page->getContent());
- $this->getSession()->visit($this->pathTo('/advanced_form.html'));
- $webAssert = $this->getAssertSession();
- $page = $this->getSession()->getPage();
- $this->assertEquals('ADvanced Form Page', $webAssert->elementExists('css', 'h1')->getText());
- $firstname = $webAssert->fieldExists('first_name');
- $lastname = $webAssert->fieldExists('lastn');
- $email = $webAssert->fieldExists('Your email:');
- $select = $webAssert->fieldExists('select_number');
- $sex = $webAssert->fieldExists('sex');
- $maillist = $webAssert->fieldExists('mail_list');
- $agreement = $webAssert->fieldExists('agreement');
- $notes = $webAssert->fieldExists('notes');
- $about = $webAssert->fieldExists('about');
- $this->assertEquals('Firstname', $firstname->getValue());
- $this->assertEquals('Lastname', $lastname->getValue());
- $this->assertEquals('your@email.com', $email->getValue());
- $this->assertEquals('20', $select->getValue());
- $this->assertEquals('w', $sex->getValue());
- $this->assertEquals('original notes', $notes->getValue());
- $this->assertEquals('on', $maillist->getValue());
- $this->assertNull($agreement->getValue());
- $this->assertTrue($maillist->isChecked());
- $this->assertFalse($agreement->isChecked());
- $agreement->check();
- $this->assertTrue($agreement->isChecked());
- $maillist->uncheck();
- $this->assertFalse($maillist->isChecked());
- $select->selectOption('thirty');
- $this->assertEquals('30', $select->getValue());
- $sex->selectOption('m');
- $this->assertEquals('m', $sex->getValue());
- $notes->setValue('new notes');
- $this->assertEquals('new notes', $notes->getValue());
- $about->attachFile($this->mapRemoteFilePath(__DIR__.'/../../web-fixtures/some_file.txt'));
- $button = $page->findButton('Register');
- $this->assertNotNull($button);
- $page->fillField('first_name', 'Foo "item"');
- $page->fillField('last_name', 'Bar');
- $page->fillField('Your email:', 'ever.zet@gmail.com');
- $this->assertEquals('Foo "item"', $firstname->getValue());
- $this->assertEquals('Bar', $lastname->getValue());
- $button->press();
- if ($this->safePageWait(5000, 'document.getElementsByTagName("title") !== null')) {
- $out = <<<OUT
- array (
- 'agreement' = 'on',
- 'email' = 'ever.zet@gmail.com',
- 'first_name' = 'Foo "item"',
- 'last_name' = 'Bar',
- 'notes' = 'new notes',
- 'select_number' = '30',
- 'sex' = 'm',
- 'submit' = 'Register',
- )
- some_file.txt
- 1 uploaded file
- OUT;
- $this->assertContains($out, $page->getContent());
- }
- }
- public function testMultiInput()
- {
- $this->getSession()->visit($this->pathTo('/multi_input_form.html'));
- $page = $this->getSession()->getPage();
- $webAssert = $this->getAssertSession();
- $this->assertEquals('Multi input Test', $webAssert->elementExists('css', 'h1')->getText());
- $first = $webAssert->fieldExists('First');
- $second = $webAssert->fieldExists('Second');
- $third = $webAssert->fieldExists('Third');
- $this->assertEquals('tag1', $first->getValue());
- $this->assertSame('tag2', $second->getValue());
- $this->assertEquals('tag1', $third->getValue());
- $first->setValue('tag2');
- $this->assertEquals('tag2', $first->getValue());
- $this->assertSame('tag2', $second->getValue());
- $this->assertEquals('tag1', $third->getValue());
- $second->setValue('one');
- $this->assertEquals('tag2', $first->getValue());
- $this->assertSame('one', $second->getValue());
- $third->setValue('tag3');
- $this->assertEquals('tag2', $first->getValue());
- $this->assertSame('one', $second->getValue());
- $this->assertEquals('tag3', $third->getValue());
- $button = $page->findButton('Register');
- $this->assertNotNull($button);
- $button->press();
- $space = ' ';
- $out = <<<OUT
- 'tags' =$space
- array (
- 0 = 'tag2',
- 1 = 'one',
- 2 = 'tag3',
- ),
- OUT;
- $this->assertContains($out, $page->getContent());
- }
- public function testAdvancedFormSecondSubmit()
- {
- $this->getSession()->visit($this->pathTo('/advanced_form.html'));
- $page = $this->getSession()->getPage();
- $button = $page->findButton('Login');
- $this->assertNotNull($button);
- $button->press();
- $toSearch = array(
- "'agreement' = 'off',",
- "'submit' = 'Login',",
- 'no file',
- );
- $pageContent = $page->getContent();
- foreach ($toSearch as $searchString) {
- $this->assertContains($searchString, $pageContent);
- }
- }
- public function testSubmitEmptyTextarea()
- {
- $this->getSession()->visit($this->pathTo('/empty_textarea.html'));
- $page = $this->getSession()->getPage();
- $page->pressButton('Save');
- $toSearch = array(
- "'textarea' = '',",
- "'submit' = 'Save',",
- 'no file',
- );
- $pageContent = $page->getContent();
- foreach ($toSearch as $searchString) {
- $this->assertContains($searchString, $pageContent);
- }
- }
- }
|