View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementMappingTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_mapping',
];
public function testMappingElement() {
$this
->drupalGet('/webform/test_element_mapping');
$this
->assertRaw('<th>Source →</th>');
$this
->assertRaw('<th>Destination</th>');
$this
->assertRaw('<select data-drupal-selector="edit-webform-mapping-one" id="edit-webform-mapping-one" name="webform_mapping[one]" class="form-select"><option value="" selected="selected">- Select -</option><option value="four">Four</option><option value="five">Five</option><option value="six">Six</option></select>');
$this
->assertRaw('<td>One →<div class="description js-form-wrapper form-wrapper" data-drupal-selector="edit-table-one-source-data-description" id="edit-table-one-source-data-description">This is a description. This is a <a href="https://google.com">link</a></div>');
$this
->assertRaw('<td>One<span data-drupal-selector="edit-table-one-source-data-help" class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="One" data-webform-help="<div class="webform-element-help--title">One</div><div class="webform-element-help--content">This is help. This is a <a href="https://google.com">link</a></div>"><span aria-hidden="true">?</span></span> →</td>');
$this
->assertRaw('<th>{Custom source} »</th>');
$this
->assertRaw('<th>{Destination source}</th>');
$this
->assertRaw('<select data-drupal-selector="edit-webform-mapping-one" id="edit-webform-mapping-one" name="webform_mapping[one]" class="form-select"><option value="" selected="selected">- Select -</option><option value="four">Four</option><option value="five">Five</option><option value="six">Six</option></select>');
$this
->assertRaw('<input data-drupal-selector="edit-webform-mapping-select-other-one-other" type="text" id="edit-webform-mapping-select-other-one-other" name="webform_mapping_select_other[one][other]" value="" size="60" maxlength="255" placeholder="Enter other…" class="form-text" />');
$this
->assertRaw('<input data-drupal-selector="edit-webform-mapping-textfield-one" type="text" id="edit-webform-mapping-textfield-one" name="webform_mapping_textfield[one]" value="" size="10" maxlength="128" class="form-text" />');
$this
->drupalPostForm('/webform/test_element_mapping', [], 'Submit');
$this
->assertRaw('webform_mapping_required field is required.');
$this
->assertRaw('One field is required.');
$this
->assertRaw('Two field is required.');
$this
->assertRaw('Three field is required.');
$this
->assertNoRaw('webform_mapping_required_all field is required.');
$edit = [
'webform_mapping[one]' => 'four',
'webform_mapping[three]' => 'six',
'webform_mapping_description[two]' => 'five',
'webform_mapping_help[two]' => 'five',
'webform_mapping_required[one]' => 'four',
'webform_mapping_required_all[one]' => 'four',
'webform_mapping_required_all[two]' => 'five',
'webform_mapping_required_all[three]' => 'six',
'webform_mapping_custom[Sunday]' => 'four',
'webform_mapping_custom[Monday]' => 'four',
'webform_mapping_custom[Tuesday]' => 'four',
'webform_mapping_custom[Wednesday]' => 'four',
'webform_mapping_custom[Thursday]' => 'four',
'webform_mapping_custom[Friday]' => 'four',
'webform_mapping_custom[Saturday]' => 'four',
'webform_mapping_select_other[one][select]' => 'five',
'webform_mapping_select_other[two][select]' => 'five',
'webform_mapping_select_other[three][select]' => '_other_',
'webform_mapping_select_other[three][other]' => '{other}',
'webform_mapping_textfield[one]' => 'Loremipsum',
'webform_mapping_textfield[two]' => 'Loremipsum',
'webform_mapping_textfield[three]' => 'Loremipsum',
'webform_mapping_email_multiple[one]' => 'example@example.com, test@test.com, random@random.com',
'webform_mapping_email_multiple[two]' => '',
'webform_mapping_email_multiple[three]' => '',
];
$this
->drupalPostForm('/webform/test_element_mapping', $edit, 'Preview');
$this
->assertRaw('<li>Two → Five</li>');
$this
->drupalPostForm('/webform/test_element_mapping', $edit, 'Submit');
$this
->assertRaw("webform_mapping:\n one: four\n three: six\nwebform_mapping_description:\n two: five\nwebform_mapping_help:\n two: five\nwebform_mapping_custom:\n Sunday: four\n Monday: four\n Tuesday: four\n Wednesday: four\n Thursday: four\n Friday: four\n Saturday: four\nwebform_mapping_required:\n one: four\nwebform_mapping_required_all:\n one: four\n two: five\n three: six\nwebform_mapping_select_other:\n one: five\n two: five\n three: '{other}'\nwebform_mapping_textfield:\n one: Loremipsum\n two: Loremipsum\n three: Loremipsum\nwebform_mapping_email_multiple:\n one: 'example@example.com, test@test.com, random@random.com'");
}
}