WebformOptionsCustomTest.php in Webform 8.5
File
modules/webform_options_custom/tests/src/Functional/WebformOptionsCustomTest.php
View source
<?php
namespace Drupal\Tests\webform_options_custom\Functional;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\Entity\Webform;
use Drupal\webform_options_custom\Entity\WebformOptionsCustom;
class WebformOptionsCustomTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'webform_options_custom',
'webform_options_custom_test',
];
public function testOptionsCustom() {
$webform = Webform::load('test_element_options_custom_html');
$this
->drupalGet('/webform/test_element_options_custom_html');
$this
->assertRaw('<div data-id="one" data-name="One" data-option-value="one">One</div>');
$this
->assertRaw('<div data-id="two" data-name="Two" data-option-value="two">Two</div>');
$this
->assertRaw('<div data-id="three" data-name="Three" data-option-value="three">Three</div>');
$this
->assertRaw('<div data-id="a" data-name="A -- This is the letter A" data-option-value="a">A</div>');
$this
->assertRaw('<div data-name="B" data-option-value="b">B</div>');
$this
->assertRaw('<div data-id="c" data-name="C" data-option-value="c">C</div>');
$this
->assertRaw('data-descriptions="{"c":"This is the letter C. [element#options]","b":"\\u003Cem\\u003EThis is the letter B\\u003C\\/em\\u003E alert(\\u0027XSS\\u0027);. [entity#options]","a":"This is the letter A"}"');
$this
->assertNoRaw('\\u003Cscript\\u003Ealert(\\u0027XSS\\u0027);\\u003C\\/script\\u003E');
$this
->postSubmission($webform);
$this
->assertRaw('webform_options_custom_html field is required.');
$this
->assertRaw('webform_options_custom_html_advanced field is required.');
$this
->postSubmission($webform, [
'webform_options_custom_html[select]' => 'one',
'webform_options_custom_html_advanced[select][]' => 'a',
], 'Preview');
$this
->assertPattern('#<label>webform_options_custom_html</label>\\s*One\\s*</div>#');
$this
->assertPattern('#<label>webform_options_custom_html_advanced</label>\\s*A\\s*</div>#');
$this
->postSubmission($webform, [
'webform_options_custom_html[select]' => 'one',
'webform_options_custom_html_advanced[select][]' => 'a',
]);
$this
->assertRaw('webform_options_custom_html: one
webform_options_custom_html_advanced:
- a');
$this
->drupalGet('/webform/css/test_element_options_custom_html');
$this
->assertRaw('.webform-options-custom--test-html-advanced [data-option-value]');
$this
->drupalGet('/webform/javascript/test_element_options_custom_html');
$this
->assertRaw("window.console && window.console.log('Test: HTML advanced loaded.');");
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/structure/webform/config/options_custom/manage/test_html/preview');
$this
->assertCssSelect('.webform-options-custom--test-html[data-fill]');
$this
->assertCssSelect('.webform-options-custom--test-html[data-tooltip]');
$this
->assertNoCssSelect('.webform-options-custom--test-html[data-select-hidden]');
$webform_options_custom = WebformOptionsCustom::load('test_html');
$webform_options_custom
->set('fill', FALSE);
$webform_options_custom
->set('tooltip', FALSE);
$webform_options_custom
->set('show_select', FALSE);
$webform_options_custom
->save();
$this
->drupalGet('/admin/structure/webform/config/options_custom/manage/test_html/preview');
$this
->assertNoCssSelect('.webform-options-custom--test-html[data-fill]');
$this
->assertNoCssSelect('.webform-options-custom--test-html[data-tooltip]');
$this
->assertCssSelect('.webform-options-custom--test-html[data-select-hidden]');
$this
->drupalGet('/admin/structure/webform/config/options_custom/manage/test_twig/preview');
$this
->assertRaw('<td data-option-value="1" style="text-align:center">1</td>');
$this
->assertRaw('<td data-option-value="2" style="text-align:center">2</td>');
$this
->assertRaw('<td data-option-value="3" style="text-align:center">3</td>');
$this
->assertNoRaw('<td data-option-value="4" style="text-align:center">4</td>');
$this
->assertNoRaw('<td data-option-value="5" style="text-align:center">5</td>');
$this
->drupalGet('/webform/test_element_options_custom_twig');
$this
->assertRaw('<td data-option-value="1" style="text-align:center">1</td>');
$this
->assertRaw('<td data-option-value="2" style="text-align:center">2</td>');
$this
->assertRaw('<td data-option-value="3" style="text-align:center">3</td>');
$this
->assertRaw('<td data-option-value="4" style="text-align:center">4</td>');
$this
->assertRaw('<td data-option-value="5" style="text-align:center">5</td>');
}
}