YamlFormElementCustomPropertiesTest.php in YAML Form 8
File
src/Tests/YamlFormElementCustomPropertiesTest.php
View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\simpletest\WebTestBase;
class YamlFormElementCustomPropertiesTest extends WebTestBase {
protected static $modules = [
'system',
'user',
'yamlform',
'yamlform_ui',
'yamlform_test_custom_properties',
];
public function testCustomProperties() {
$admin_user = $this
->drupalCreateUser([
'administer yamlform',
]);
$this
->drupalLogin($admin_user);
$yamlform_storage = \Drupal::entityTypeManager()
->getStorage('yamlform');
$yamlform = $yamlform_storage
->load('contact');
$name_element = [
'#type' => 'textfield',
'#title' => 'Your Name',
'#default_value' => '[yamlform-authenticated-user:display-name]',
'#required' => TRUE,
];
$this
->assertEqual($yamlform
->getElementDecoded('name'), $name_element);
$this
->drupalGet('yamlform/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/yamlform/manage/contact/element/name/edit', $edit, t('Save'));
$yamlform_storage
->resetCache();
$yamlform = $yamlform_storage
->load('contact');
$this
->assertEqual($yamlform
->getElementDecoded('name'), $name_element);
$edit = [
'properties[custom_data]' => 'custom-data',
];
$this
->drupalPostForm('admin/structure/yamlform/manage/contact/element/name/edit', $edit, t('Save'));
$yamlform_storage
->resetCache();
$yamlform = $yamlform_storage
->load('contact');
$name_element += [
'#custom_data' => 'custom-data',
];
$this
->assertEqual($yamlform
->getElementDecoded('name'), $name_element);
$this
->drupalGet('yamlform/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" />');
}
}