public function WebformElementStatesSelectorsTest::testSelectors in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Functional/Element/WebformElementStatesSelectorsTest.php \Drupal\Tests\webform\Functional\Element\WebformElementStatesSelectorsTest::testSelectors()
Tests element #states selectors for basic and composite elements.
File
- tests/
src/ Functional/ Element/ WebformElementStatesSelectorsTest.php, line 52
Class
- WebformElementStatesSelectorsTest
- Tests for webform element #states selectors.
Namespace
Drupal\Tests\webform\Functional\ElementCode
public function testSelectors() {
foreach ([
'test_example_elements',
'test_example_elements_composite',
] as $webform_id) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = Webform::load($webform_id);
$webform
->setStatus(WebformInterface::STATUS_OPEN)
->save();
$this
->drupalGet('/webform/' . $webform_id);
$selectors = OptGroup::flattenOptions($webform
->getElementsSelectorOptions());
// Ignore text format and captcha selectors which are not available during
// this test.
unset($selectors[':input[name="text_format[format]"]'], $selectors[':input[name="captcha"]']);
foreach ($selectors as $selector => $name) {
// Remove :input since it is a jQuery specific selector.
$selector = str_replace(':input', '', $selector);
$this
->assertCssSelect($selector);
}
}
$webform = Webform::load('test_example_elements');
// Check the value element is excluded.
$selectors = $webform
->getElementsSelectorOptions();
$this
->assertArrayNotHasKey(':input[name="value"]', $selectors);
// Check the value element is included.
$selectors = $webform
->getElementsSelectorOptions([
'excluded_elements' => [],
]);
$this
->assertEqual($selectors[':input[name="value"]'], 'Value [Value]');
}