WebformElementLikertTest.php in Webform 6.x
File
tests/src/Functional/Element/WebformElementLikertTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementLikertTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_likert',
];
public function testLikertElement() {
$this
->drupalGet('/webform/test_element_likert');
$this
->assertRaw('<table class="webform-likert-table sticky-enabled responsive-enabled" data-likert-answers-count="3" data-drupal-selector="edit-likert-default-table" id="edit-likert-default-table" data-striping="1">');
$this
->assertPattern('#<tr>\\s+<th><span class="visually-hidden">Questions</span></th>\\s+<th>Option 1</th>\\s+<th>Option 2</th>\\s+<th>Option 3</th>\\s+</tr>#');
$this
->assertRaw('<label>Question 1</label>');
$this
->assertRaw('<td><div class="js-form-item form-item js-form-type-radio form-item-likert-default-q1 js-form-item-likert-default-q1">');
$this
->assertRaw('<input aria-labelledby="edit-likert-default-table-q1-likert-question" data-drupal-selector="edit-likert-default-q1" type="radio" id="edit-likert-default-q1" name="likert_default[q1]" value="1" class="form-radio" />');
$this
->assertRaw('<label for="edit-likert-default-q1" class="option"><span class="webform-likert-label visually-hidden">Option 1</span></label>');
$this
->assertPattern('#<tr>\\s+<th><span class="visually-hidden">Questions</span></th>\\s+<th>Option 1</th>\\s+<th>Option 2</th>\\s+<th>Option 3</th>\\s+<th>Not applicable</th>\\s+</tr>#');
$this
->assertRaw('<td><div class="js-form-item form-item js-form-type-radio form-item-likert-advanced-q1 js-form-item-likert-advanced-q1">');
$this
->assertRaw('<input aria-labelledby="edit-likert-advanced-table-q1-likert-question" required="required" aria-required="true" data-drupal-selector="edit-likert-advanced-q1" type="radio" id="edit-likert-advanced-q1--4" name="likert_advanced[q1]" value="N/A" class="form-radio" />');
$this
->assertRaw('<label for="edit-likert-advanced-q1--4" class="option"><span class="webform-likert-label visually-hidden">Not applicable</span></label>');
$this
->assertRaw('<th>Option 1<div class="description">This is a description</div>');
$this
->assertRaw('<label>Question 1</label>');
$this
->assertRaw('<div id="edit-likert-description-table-q1-likert-question--description" class="webform-element-description">');
$this
->assertRaw('<label for="edit-likert-description-q1" class="option"><span class="webform-likert-label visually-hidden">Option 1</span></label>');
$this
->assertRaw('<span class="webform-likert-description hidden">This is a description</span>');
$this
->assertRaw('<th>Option 1<span class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="Option 1" data-webform-help="<div class="webform-element-help--title">Option 1</div><div class="webform-element-help--content">This is help text</div>"><span aria-hidden="true">?</span></span>');
$this
->assertRaw('<label>Question 1<span class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="Question 1" data-webform-help="<div class="webform-element-help--title">Question 1</div><div class="webform-element-help--content">This is help text</div>"><span aria-hidden="true">?</span></span>');
$this
->assertRaw('<label for="edit-likert-help-q1--2" class="option"><span class="webform-likert-label visually-hidden">Option 2<span class="webform-likert-help hidden"><span class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="Option 2" data-webform-help="<div class="webform-element-help--title">Option 2</div><div class="webform-element-help--content">This is help text</div>"><span aria-hidden="true">?</span></span>');
$this
->drupalPostForm('/webform/test_element_likert', [], 'Submit');
$this
->assertNoRaw('Question 1 field is required.');
$this
->assertNoRaw('Question 2 field is required.');
$this
->assertNoRaw('Question 3 field is required.');
$this
->assertRaw('{custom error for Question 1}');
$this
->assertRaw('{custom error for Question 2}');
$this
->assertRaw('{custom error for Question 3}');
$edit = [
'likert_advanced[q1]' => '1',
'likert_advanced[q2]' => '2',
'likert_advanced[q3]' => 'N/A',
'likert_values[0]' => '0',
'likert_values[1]' => '1',
'likert_values[2]' => 'N/A',
];
$this
->drupalPostForm('/webform/test_element_likert', $edit, 'Submit');
$this
->assertRaw("likert_default:\n q1: null\n q2: null\n q3: null\nlikert_advanced:\n q1: '1'\n q2: '2'\n q3: N/A\nlikert_description:\n q1: null\n q2: null\n q3: null\nlikert_help:\n q1: null\n q2: null\n q3: null\nlikert_values:\n - '0'\n - '1'\n - N/A");
}
}