DynamicFormSectionsTest.php
Namespace
Drupal\Tests\ajax_example\Functional
File
-
modules/ajax_example/tests/src/Functional/DynamicFormSectionsTest.php
View source
<?php
namespace Drupal\Tests\ajax_example\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class DynamicFormSectionsTest extends BrowserTestBase {
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' => 'nojs',
]);
$this->drupalGet($dropdown_url);
$detail_children = $page->findAll('css', 'div.details-wrapper *');
$this->assertEmpty($detail_children);
$this->drupalGet($dropdown_url);
$this->submitForm([
'question_type_select' => 'Choose question style',
], 'Choose');
$detail_children = $page->findAll('css', 'div.details-wrapper *');
$this->assertEquals(count($detail_children), 0);
$question_styles = [
'Multiple Choice',
'True/False',
'Fill-in-the-blanks',
];
foreach ($question_styles as $question_style) {
$this->drupalGet($dropdown_url);
$this->submitForm([
'question_type_select' => $question_style,
], 'Choose');
$detail_children = $page->findAll('css', 'div.details-wrapper *');
$this->assertNotEquals($this->count($detail_children), 0);
$this->submitForm([
'question' => 'George Washington',
], 'Submit your answer');
$assert->pageTextContains('You got the right answer: George Washington');
}
$this->drupalGet($dropdown_url);
$this->submitForm([
'question_type_select' => 'Multiple Choice',
], 'Choose');
$detail_children = $page->findAll('css', 'div.details-wrapper *');
$this->assertNotEquals($this->count($detail_children), 0);
$this->submitForm([
'question' => 'Abraham Lincoln',
], 'Submit your answer');
$assert->pageTextContains('Sorry, your answer (Abraham Lincoln) is wrong');
}
}
Classes