function JavascriptStatesTest::doCheckboxesTriggerTests
Same name in other branches
- 9 core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.php \Drupal\FunctionalJavascriptTests\Core\Form\JavascriptStatesTest::doCheckboxesTriggerTests()
- 10 core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.php \Drupal\FunctionalJavascriptTests\Core\Form\JavascriptStatesTest::doCheckboxesTriggerTests()
Tests states of elements triggered by a checkboxes element.
1 call to JavascriptStatesTest::doCheckboxesTriggerTests()
- JavascriptStatesTest::testJavascriptStates in core/
tests/ Drupal/ FunctionalJavascriptTests/ Core/ Form/ JavascriptStatesTest.php - Tests the JavaScript #states functionality of form elements.
File
-
core/
tests/ Drupal/ FunctionalJavascriptTests/ Core/ Form/ JavascriptStatesTest.php, line 277
Class
- JavascriptStatesTest
- Tests the state of elements based on another elements.
Namespace
Drupal\FunctionalJavascriptTests\Core\FormCode
protected function doCheckboxesTriggerTests() : void {
$this->drupalGet('form-test/javascript-states-form');
$page = $this->getSession()
->getPage();
// Find trigger and target elements.
$trigger_value1 = $page->findField('checkboxes_trigger[value1]');
$this->assertNotEmpty($trigger_value1);
$trigger_value2 = $page->findField('checkboxes_trigger[value2]');
$this->assertNotEmpty($trigger_value2);
$trigger_value3 = $page->findField('checkboxes_trigger[value3]');
$this->assertNotEmpty($trigger_value3);
$textfield_visible_value2 = $page->findField('textfield_visible_when_checkboxes_trigger_value2_checked');
$this->assertNotEmpty($textfield_visible_value2);
$textfield_visible_value3 = $page->findField('textfield_visible_when_checkboxes_trigger_value3_checked');
$this->assertNotEmpty($textfield_visible_value3);
// Verify initial state.
$this->assertFalse($textfield_visible_value2->isVisible());
$this->assertFalse($textfield_visible_value3->isVisible());
// Change state: check the 'Value 1' checkbox.
$trigger_value1->check();
$this->assertFalse($textfield_visible_value2->isVisible());
$this->assertFalse($textfield_visible_value3->isVisible());
// Change state: check the 'Value 2' checkbox.
$trigger_value2->check();
$this->assertTrue($textfield_visible_value2->isVisible());
$this->assertFalse($textfield_visible_value3->isVisible());
// Change state: check the 'Value 3' checkbox.
$trigger_value3->check();
$this->assertTrue($textfield_visible_value2->isVisible());
$this->assertTrue($textfield_visible_value3->isVisible());
// Change state: uncheck the 'Value 2' checkbox.
$trigger_value2->uncheck();
$this->assertFalse($textfield_visible_value2->isVisible());
$this->assertTrue($textfield_visible_value3->isVisible());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.