function AjaxColorFormTest::testAjaxColorForm
Same name in other branches
- 3.x modules/form_api_example/tests/src/FunctionalJavascript/AjaxColorFormTest.php \Drupal\Tests\form_api_example\FunctionalJavascript\AjaxColorFormTest::testAjaxColorForm()
Functional test of the color temperature AJAX dropdown form.
File
-
modules/
form_api_example/ tests/ src/ FunctionalJavascript/ AjaxColorFormTest.php, line 30
Class
- AjaxColorFormTest
- @group form_api_example
Namespace
Drupal\Tests\form_api_example\FunctionalJavascriptCode
public function testAjaxColorForm() {
// Visit form route.
$this->drupalGet(Url::fromRoute('form_api_example.ajax_color_demo'));
// Get Mink stuff.
$assert = $this->assertSession();
// Before the color temperature dropdown is selected, we should not have a
// color dropdown.
$assert->fieldNotExists('color');
$color_matrix = [
'warm' => [
'red',
'orange',
'yellow',
],
'cool' => [
'blue',
'purple',
'green',
],
];
foreach ($color_matrix as $temperature => $colors) {
// Submit all the colors.
foreach ($colors as $color) {
$assert->selectExists('temperature')
->selectOption($temperature);
$assert->assertWaitOnAjaxRequest();
$assert->selectExists('color')
->selectOption($color);
$assert->buttonExists('Submit')
->press();
$assert->pageTextContains("Value for Temperature: {$temperature}");
$assert->pageTextContains("Value for color: {$color}");
}
}
$assert->selectExists('temperature')
->selectOption('');
$assert->assertWaitOnAjaxRequest();
$assert->fieldNotExists('color');
}