protected function JavascriptStatesTest::doCheckboxesTriggerTests in Drupal 10
Same name and namespace in other branches
- 9 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 124
Class
- JavascriptStatesTest
- Tests the state of elements based on another elements.
Namespace
Drupal\FunctionalJavascriptTests\Core\FormCode
protected function doCheckboxesTriggerTests() {
$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());
}