WebformElementCodeMirrorTest.php in Webform 6.x
File
tests/src/Functional/Element/WebformElementCodeMirrorTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementCodeMirrorTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_codemirror',
];
public function testCodeMirror() {
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<label for="edit-text-basic">text_basic</label>');
$this
->assertRaw('<textarea data-drupal-selector="edit-text-basic" class="js-webform-codemirror webform-codemirror text form-textarea" data-webform-codemirror-mode="text/plain" id="edit-text-basic" name="text_basic" rows="5" cols="60">Hello</textarea>');
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<label for="edit-text-basic-no-wrap">text_basic_no_wrap</label>');
$this
->assertRaw('<textarea data-drupal-selector="edit-text-basic-no-wrap" wrap="off" class="js-webform-codemirror webform-codemirror text form-textarea" data-webform-codemirror-mode="text/plain" id="edit-text-basic-no-wrap" name="text_basic_no_wrap" rows="5" cols="60">');
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<label for="edit-yaml-basic">yaml_basic</label>');
$this
->assertRaw('<textarea data-drupal-selector="edit-yaml-basic" class="js-webform-codemirror webform-codemirror yaml form-textarea" data-webform-codemirror-mode="text/x-yaml" id="edit-yaml-basic" name="yaml_basic" rows="5" cols="60">test: hello</textarea>');
$this
->drupalPostForm('/webform/test_element_codemirror', [], 'Submit');
$this
->assertRaw("yaml_basic: 'test: hello'\nyaml_array:\n one: One\n two: Two\n three: Three\nyaml_indexed_array:\n - one\nyaml_indexed_associative_array:\n - one: One\nyaml_decode_value:\n test: hello");
$edit = [
'yaml_basic' => "'not: valid",
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertRaw('<em class="placeholder">yaml_basic</em> is not valid.');
$edit = [
'yaml_basic' => 'is: valid',
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertNoRaw('<em class="placeholder">yaml_basic</em> is not valid.');
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<label for="edit-html-basic">html_basic</label>');
$this
->assertRaw('<textarea data-drupal-selector="edit-html-basic" class="js-webform-codemirror webform-codemirror html form-textarea" data-webform-codemirror-mode="text/html" id="edit-html-basic" name="html_basic" rows="5" cols="60"><b>Hello</b></textarea>');
$edit = [
'html_basic' => "<b>bold</bold>",
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertRaw('<em class="placeholder">html_basic</em> is not valid.');
$this
->assertRaw('expected '>'');
$edit = [
'html_basic' => '<b>bold</b>',
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertNoRaw('<em class="placeholder">html_basic</em> is not valid.');
$this
->assertNoRaw('expected '>'');
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<label for="edit-twig-basic">twig_basic</label>');
$this
->assertRaw('<textarea data-drupal-selector="edit-twig-basic" disabled="disabled" class="js-webform-codemirror webform-codemirror twig form-textarea" data-webform-codemirror-mode="twig" id="edit-twig-basic" name="twig_basic" rows="5" cols="60">
{% set value = "Hello" %}
{{ value }}
</textarea>');
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform/test_element_codemirror');
$this
->assertRaw('<textarea data-drupal-selector="edit-twig-basic" class="js-webform-codemirror webform-codemirror twig form-textarea" data-webform-codemirror-mode="twig" id="edit-twig-basic" name="twig_basic" rows="5" cols="60">
{% set value = "Hello" %}
{{ value }}
</textarea>');
$edit = [
'twig_basic' => 'Can edit Twig template.',
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertRaw('Can edit Twig template.');
$edit = [
'twig_basic' => "{{ value ",
];
$this
->drupalPostForm('/webform/test_element_codemirror', $edit, 'Submit');
$this
->assertRaw('<em class="placeholder">twig_basic</em> is not valid.');
$this
->assertRaw('Unclosed "variable" in');
}
}