WebformElementStatesSelectorsTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementStatesSelectorsTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\Core\Form\OptGroup;
use Drupal\webform\Entity\Webform;
use Drupal\webform\WebformInterface;
class WebformElementStatesSelectorsTest extends WebformElementBrowserTestBase {
public static $modules = [
'filter',
'file',
'language',
'taxonomy',
'node',
'webform',
];
protected static $testWebforms = [
'test_example_elements',
'test_example_elements_composite',
];
protected function setUp() {
parent::setUp();
$this
->createTags();
\Drupal::configFactory()
->getEditable('webform.settings')
->set('libraries.excluded_libraries', [])
->save();
\Drupal::configFactory()
->getEditable('webform.settings')
->set('element.excluded_elements', [])
->save();
}
public function testSelectors() {
foreach ([
'test_example_elements',
'test_example_elements_composite',
] as $webform_id) {
$webform = Webform::load($webform_id);
$webform
->setStatus(WebformInterface::STATUS_OPEN)
->save();
$this
->drupalGet('/webform/' . $webform_id);
$selectors = OptGroup::flattenOptions($webform
->getElementsSelectorOptions());
unset($selectors[':input[name="text_format[format]"]'], $selectors[':input[name="captcha"]']);
foreach ($selectors as $selector => $name) {
$selector = str_replace(':input', '', $selector);
$this
->assertCssSelect($selector);
}
}
$webform = Webform::load('test_example_elements');
$selectors = $webform
->getElementsSelectorOptions();
$this
->assertArrayNotHasKey(':input[name="value"]', $selectors);
$selectors = $webform
->getElementsSelectorOptions([
'excluded_elements' => [],
]);
$this
->assertEqual($selectors[':input[name="value"]'], 'Value [Value]');
}
}