Namespace
Drupal\Tests\form_api_example\FunctionalJavascript
File
-
modules/form_api_example/tests/src/FunctionalJavascript/AjaxColorFormTest.php
View source
<?php
namespace Drupal\Tests\form_api_example\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Core\Url;
class AjaxColorFormTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'form_api_example',
];
public function testAjaxColorForm() {
$this->drupalGet(Url::fromRoute('form_api_example.ajax_color_demo'));
$assert = $this->assertSession();
$assert->fieldNotExists('color');
$color_matrix = [
'warm' => [
'red',
'orange',
'yellow',
],
'cool' => [
'blue',
'purple',
'green',
],
];
foreach ($color_matrix as $temperature => $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');
}
}
Classes
| Title |
Deprecated |
Summary |
| AjaxColorFormTest |
|
Tests the behavior of the color temperature AJAX dropdown form. |