WebformExampleElementPropertiesTest.php in Webform 8.5
File
modules/webform_example_element_properties/tests/src/Functional/WebformExampleElementPropertiesTest.php
View source
<?php
namespace Drupal\Tests\webform_example_element_properties\Functiona;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformExampleElementPropertiesTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'webform_ui',
'webform_example_element_properties',
];
public function testCustomProperties() {
$admin_user = $this
->drupalCreateUser([
'administer webform',
]);
$this
->drupalLogin($admin_user);
$webform_storage = \Drupal::entityTypeManager()
->getStorage('webform');
$webform = $webform_storage
->load('contact');
$name_element = [
'#type' => 'textfield',
'#title' => 'Your Name',
'#default_value' => '[current-user:display-name]',
'#required' => TRUE,
];
$this
->assertEqual($webform
->getElementDecoded('name'), $name_element);
$this
->drupalGet('/webform/contact');
$this
->assertRaw('<input data-drupal-selector="edit-name" type="text" id="edit-name" name="name" value="' . htmlentities($admin_user
->label()) . '" size="60" maxlength="255" class="form-text required" required="required" aria-required="true" />');
$edit = [
'properties[custom_data]' => '',
];
$this
->drupalPostForm('/admin/structure/webform/manage/contact/element/name/edit', $edit, 'Save');
$webform_storage
->resetCache();
$webform = $webform_storage
->load('contact');
$this
->assertEqual($webform
->getElementDecoded('name'), $name_element);
$edit = [
'properties[custom_data]' => 'custom-data',
];
$this
->drupalPostForm('/admin/structure/webform/manage/contact/element/name/edit', $edit, 'Save');
$webform_storage
->resetCache();
$webform = $webform_storage
->load('contact');
$name_element += [
'#custom_data' => 'custom-data',
];
$this
->assertEqual($webform
->getElementDecoded('name'), $name_element);
$this
->drupalGet('/webform/contact');
$this
->assertRaw('<input data-custom="custom-data" data-drupal-selector="edit-name" type="text" id="edit-name" name="name" value="' . htmlentities($admin_user
->label()) . '" size="60" maxlength="255" class="form-text required" required="required" aria-required="true" />');
}
}