View source
<?php
namespace Drupal\Tests\webform_image_select\Functional;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\Element\WebformElementBrowserTestBase;
class WebformImageSelectElementTest extends WebformElementBrowserTestBase {
public static $modules = [
'webform',
'webform_image_select',
'webform_image_select_test',
];
public function testImageSelect() {
$this
->drupalGet('/webform/test_element_image_select');
$this
->assertRaw('<select data-drupal-selector="edit-image-select-default" data-images="{"kitten_1":{"text":"Cute Kitten 1","src":"http:\\/\\/placekitten.com\\/220\\/200"},"kitten_2":{"text":"Cute Kitten 2","src":"http:\\/\\/placekitten.com\\/180\\/200"},"kitten_3":{"text":"Cute Kitten 3","src":"http:\\/\\/placekitten.com\\/130\\/200"},"kitten_4":{"text":"Cute Kitten 4","src":"http:\\/\\/placekitten.com\\/270\\/200"}}" class="webform-image-select js-webform-image-select form-select required" id="edit-image-select-default" name="image_select_default" required="required" aria-required="true">');
$this
->assertRaw('<select data-limit="2" data-drupal-selector="edit-image-select-limit" data-images="{"kitten_1":{"text":"Cute Kitten 1","src":"http:\\/\\/placekitten.com\\/220\\/200"},"kitten_2":{"text":"Cute Kitten 2","src":"http:\\/\\/placekitten.com\\/180\\/200"},"kitten_3":{"text":"Cute Kitten 3","src":"http:\\/\\/placekitten.com\\/130\\/200"},"kitten_4":{"text":"Cute Kitten 4","src":"http:\\/\\/placekitten.com\\/270\\/200"}}" class="webform-image-select js-webform-image-select form-select" multiple="multiple" name="image_select_limit[]" id="edit-image-select-limit">');
$this
->assertRaw('<select data-drupal-selector="edit-image-select-html" data-show-label="data-show-label" data-images="{"\\u003C1\\u003E":{"text":"Cute \\u003Cb style=\\u0022color:red\\u0022\\u003EKitten\\u003C\\/b\\u003E 1","src":"http:\\/\\/placekitten.com\\/220\\/200"},"\\u00222\\u0022":{"text":"Cute \\u003Cem style=\\u0022color:blue\\u0022\\u003EKitten\\u003C\\/em\\u003E 2","src":"http:\\/\\/placekitten.com\\/180\\/200"},"\\u00263":{"text":"Cute \\u003Cu style=\\u0022color:green\\u0022\\u003EKitten\\u003C\\/u\\u003E 3","src":"http:\\/\\/placekitten.com\\/130\\/200"},"4":{"text":"Cute Kitten 4 alert(\\u0022XSS\\u0022);","src":"http:\\/\\/placekitten.com\\/270\\/200"}}" class="webform-image-select js-webform-image-select form-select" id="edit-image-select-html" name="image_select_html"><option value="" selected="selected">- None -</option><option value="<1>">Cute Kitten 1</option><option value=""2"">Cute Kitten 2</option><option value="&3">Cute Kitten 3</option><option value="4">Cute Kitten 4 alert("XSS");</option></select>');
$this
->assertRaw('<input class="webform-form-filter-text form-search" data-focus="false" data-item-singlular="animal" data-item-plural="animals" data-summary=".js-image-select-filter-custom-filter .webform-image-select-summary" data-no-results=".js-image-select-filter-custom-filter .webform-image-select-no-results" data-element=".js-image-select-filter-custom-filter .thumbnails" data-source=".thumbnail p" data-parent="li" data-selected=".selected" title="Enter a keyword to filter by." type="search" id="edit-image-select-filter-custom-filter" name="image_select_filter_custom_filter" size="30" maxlength="128" placeholder="Find an animal" />');
$this
->assertRaw('<span class="field-suffix"><span class="webform-image-select-summary">8 animals</span>');
$this
->assertRaw('<div style="display:none" class="webform-image-select-no-results webform-message js-webform-message">');
$this
->assertRaw('No animals found.');
$webform = Webform::load('test_element_image_select');
$edit = [
'image_select_default' => 'kitten_1',
];
$this
->postSubmission($webform, $edit, 'Preview');
if (floatval(\Drupal::VERSION) >= 9.1) {
$this
->assertRaw('<figure style="display: inline-block; margin: 0 6px 6px 0; padding: 6px; border: 1px solid #ddd;width: 220px"><img src="http://placekitten.com/220/200" width="220" height="200" alt="Cute Kitten 1" title="Cute Kitten 1" loading="lazy" />');
}
else {
$this
->assertRaw('<figure style="display: inline-block; margin: 0 6px 6px 0; padding: 6px; border: 1px solid #ddd;width: 220px"><img src="http://placekitten.com/220/200" width="220" height="200" alt="Cute Kitten 1" title="Cute Kitten 1" />');
}
}
}