AjaxWizardTest.php in Examples for Developers 3.x
File
modules/ajax_example/tests/src/FunctionalJavascript/AjaxWizardTest.php
View source
<?php
namespace Drupal\Tests\ajax_example\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class AjaxWizardTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'ajax_example',
];
public function testWizardSteps() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert = $this
->assertSession();
$form_url = Url::fromRoute('ajax_example.wizard');
$this
->drupalGet($form_url);
$assert
->fieldExists('name');
$assert
->fieldNotExists('address');
$assert
->fieldNotExists('city');
$assert
->buttonExists('Next step');
$assert
->buttonNotExists('Previous step');
$assert
->buttonNotExists('Submit your information');
$page
->fillField('name', 'José Saramago');
$page
->pressButton('Next step');
$assert
->assertWaitOnAjaxRequest();
$assert
->fieldExists('address');
$assert
->fieldNotExists('name');
$assert
->fieldNotExists('city');
$assert
->buttonExists('Next step');
$assert
->buttonExists('Previous step');
$assert
->buttonNotExists('Submit your information');
$page
->fillField('address', 'Rua dos Bacalhoeiros, 10');
$page
->pressButton('Next step');
$assert
->assertWaitOnAjaxRequest();
$assert
->fieldExists('city');
$assert
->fieldNotExists('name');
$assert
->fieldNotExists('address');
$assert
->buttonNotExists('Next step');
$assert
->buttonExists('Previous step');
$assert
->buttonExists('Submit your information');
$page
->fillField('city', 'Lisboa');
$page
->pressButton('Submit your information');
$assert
->pageTextContains('Your information has been submitted:');
$assert
->pageTextContains('Name: José Saramago');
$assert
->pageTextContains('Address: Rua dos Bacalhoeiros, 10');
$assert
->pageTextContains('City: Lisboa');
}
public function testWizardPreviousStepsValues() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert = $this
->assertSession();
$form_url = Url::fromRoute('ajax_example.wizard');
$this
->drupalGet($form_url);
$page
->fillField('name', 'José Saramago');
$page
->pressButton('Next step');
$assert
->assertWaitOnAjaxRequest();
$page
->fillField('address', 'Rua dos Bacalhoeiros, 10');
$page
->pressButton('Next step');
$assert
->assertWaitOnAjaxRequest();
$page
->fillField('city', 'Lisboa');
$page
->pressButton('Previous step');
$assert
->assertWaitOnAjaxRequest();
$assert
->fieldValueEquals('address', 'Rua dos Bacalhoeiros, 10');
$page
->pressButton('Previous step');
$assert
->assertWaitOnAjaxRequest();
$assert
->fieldValueEquals('name', 'José Saramago');
}
}