DynamicFormSectionsTest.php
View source
<?php
namespace Drupal\Tests\ajax_example\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class DynamicFormSectionsTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'ajax_example',
];
public function testDynamicFormSections() {
$assert = $this->assertSession();
$page = $this->getSession()
->getPage();
$dropdown_url = Url::fromRoute('ajax_example.dynamic_form_sections', [
'nojs' => 'ajax',
]);
$this->drupalGet($dropdown_url);
$this->assertEmpty($page->findAll('css', 'questions-wrapper *'));
$question_styles = [
'Multiple Choice',
'True/False',
'Fill-in-the-blanks',
];
foreach ($question_styles as $question_style) {
$assert->selectExists('question_type_select')
->selectOption($question_style);
$assert->assertWaitOnAjaxRequest();
$this->assertNotEmpty($page->findAll('css', '.questions-wrapper *'));
}
$assert->selectExists('question_type_select')
->selectOption('Choose question style');
$assert->assertWaitOnAjaxRequest();
$this->assertEmpty($page->findAll('css', 'questions-wrapper *'));
foreach ($question_styles as $question_style) {
$this->drupalGet($dropdown_url);
$assert->selectExists('question_type_select')
->selectOption($question_style);
$assert->assertWaitOnAjaxRequest();
$this->submitForm([
'question' => 'George Washington',
], 'Submit your answer');
$assert->pageTextContains('You got the right answer: George Washington');
}
}
}