YamlFormAdminSettingsTest.php in YAML Form 8
File
src/Tests/YamlFormAdminSettingsTest.php
View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\Component\Serialization\Yaml;
use Drupal\yamlform\Utility\YamlFormTidy;
class YamlFormAdminSettingsTest extends YamlFormTestBase {
protected static $modules = [
'system',
'block',
'node',
'user',
'yamlform',
'yamlform_ui',
'yamlform_test',
];
public function testAdminSettings() {
global $base_path;
$this
->drupalLogin($this->adminFormUser);
$original_data = \Drupal::configFactory()
->getEditable('yamlform.settings')
->getRawData();
$this
->drupalPostForm('admin/structure/yamlform/settings', [], t('Save configuration'));
\Drupal::configFactory()
->reset('yamlform.settings');
$updated_data = \Drupal::configFactory()
->getEditable('yamlform.settings')
->getRawData();
$this
->assertEqual($updated_data, $original_data, 'Updated admin settings via the UI did not lose or change any data');
$this
->verbose('<pre>' . YamlFormTidy::tidy(Yaml::encode($original_data)) . '</pre>');
$this
->verbose('<pre>' . YamlFormTidy::tidy(Yaml::encode($updated_data)) . '</pre>');
$this
->drupalGet('yamlform/test_element');
$this
->assertPattern('#\\{item title\\}.+\\{item markup\\}.+\\{item description\\}#ms');
$this
->drupalPostForm('admin/structure/yamlform/settings', [
'elements[default_description_display]' => 'before',
], t('Save configuration'));
$this
->drupalGet('yamlform/test_element');
$this
->assertNoPattern('#\\{item title\\}.+\\{item markup\\}.+\\{item description\\}#ms');
$this
->assertPattern('#\\{item title\\}.+\\{item description\\}.+\\{item markup\\}#ms');
$this
->drupalGet('admin/structure/yamlform');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/yamlform/add" class="button button-action button--primary button--small use-ajax" data-dialog-type="modal" data-dialog-options="{"width":640}">Add form</a>');
$this
->drupalPostForm('admin/structure/yamlform/settings', [
'ui[dialog_disabled]' => TRUE,
], t('Save configuration'));
$this
->drupalGet('admin/structure/yamlform');
$this
->assertNoRaw('<a href="' . $base_path . 'admin/structure/yamlform/add" class="button button-action button--primary button--small use-ajax" data-dialog-type="modal" data-dialog-options="{"width":640}">Add form</a>');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/yamlform/add" class="button button-action button--primary button--small">Add form</a>');
$this
->drupalGet('yamlform/test_element_html_editor');
$this
->assertRaw('<textarea data-drupal-selector="edit-yamlform-html-editor" id="edit-yamlform-html-editor" name="yamlform_html_editor" rows="5" cols="60" class="form-textarea resize-vertical">Hello <b>World!!!</b></textarea>');
$this
->drupalPostForm('admin/structure/yamlform/settings', [
'ui[html_editor_disabled]' => TRUE,
], t('Save configuration'));
$this
->drupalGet('yamlform/test_element_html_editor');
$this
->assertNoRaw('<textarea data-drupal-selector="edit-yamlform-html-editor" id="edit-yamlform-html-editor" name="yamlform_html_editor" rows="5" cols="60" class="form-textarea resize-vertical">Hello <b>World!!!</b></textarea>');
$this
->assertRaw('<textarea data-drupal-selector="edit-yamlform-html-editor" class="js-yamlform-codemirror yamlform-codemirror html form-textarea resize-vertical" data-yamlform-codemirror-mode="text/html" id="edit-yamlform-html-editor" name="yamlform_html_editor" rows="5" cols="60">Hello <b>World!!!</b></textarea>');
}
}