View source
<?php
namespace Drupal\Tests\webform\Functional\Settings;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
use Drupal\webform\Utility\WebformYaml;
class WebformSettingsAdminTest extends WebformBrowserTestBase {
public static $modules = [
'block',
'captcha',
'node',
'toolbar',
'views',
'webform',
'webform_ui',
'webform_node',
];
protected static $testWebforms = [
'test_element',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
}
public function testAdminSettings() {
global $base_path;
$this
->drupalLogin($this->rootUser);
$original_data = \Drupal::configFactory()
->getEditable('webform.settings')
->getRawData();
$types = [
'forms' => 'admin/structure/webform/config',
'elements' => 'admin/structure/webform/config/elements',
'submissions' => 'admin/structure/webform/config/submissions',
'handlers' => 'admin/structure/webform/config/handlers',
'exporters' => 'admin/structure/webform/config/exporters',
'libraries' => 'admin/structure/webform/config/libraries',
'advanced' => 'admin/structure/webform/config/advanced',
];
foreach ($types as $path) {
$this
->drupalPostForm($path, [], 'Save configuration');
\Drupal::configFactory()
->reset('webform.settings');
$updated_data = \Drupal::configFactory()
->getEditable('webform.settings')
->getRawData();
$this
->ksort($updated_data);
$this
->assertEqual($updated_data, $original_data, 'Updated admin settings via the UI did not lose or change any data');
$original_yaml = WebformYaml::encode($original_data);
$updated_yaml = WebformYaml::encode($updated_data);
$this
->verbose('<pre>' . $original_yaml . '</pre>');
$this
->verbose('<pre>' . $updated_yaml . '</pre>');
$this
->debug(array_diff(explode(PHP_EOL, $original_yaml), explode(PHP_EOL, $updated_yaml)));
}
$this
->drupalGet('/webform/test_element');
$this
->assertPattern('#\\{item title\\}.+\\{item markup\\}.+\\{item description\\}#ms');
$this
->drupalPostForm('/admin/structure/webform/config/elements', [
'element[default_description_display]' => 'before',
], 'Save configuration');
$this
->drupalGet('/webform/test_element');
$this
->assertNoPattern('#\\{item title\\}.+\\{item markup\\}.+\\{item description\\}#ms');
$this
->assertPattern('#\\{item title\\}.+\\{item description\\}.+\\{item markup\\}#ms');
$this
->drupalGet('/admin/structure/webform');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/webform/add" class="webform-ajax-link button button-action" data-dialog-type="modal" data-dialog-options="{"width":700,"dialogClass":"webform-ui-dialog"}" data-drupal-link-system-path="admin/structure/webform/add">Add webform</a>');
$this
->drupalPostForm('/admin/structure/webform/config/advanced', [
'ui[dialog_disabled]' => TRUE,
], 'Save configuration');
$this
->drupalGet('/admin/structure/webform');
$this
->assertNoRaw('<a href="' . $base_path . 'admin/structure/webform/add" class="webform-ajax-link button button-action" data-dialog-type="modal" data-dialog-options="{"width":700,"dialogClass":"webform-ui-dialog"}" data-drupal-link-system-path="admin/structure/webform/add">Add webform</a>');
$this
->assertRaw('<a href="' . $base_path . 'admin/structure/webform/add" class="button button-action" data-drupal-link-system-path="admin/structure/webform/add">Add webform</a>');
$this
->drupalPostForm('/admin/structure/webform/config/advanced', [
'ui[description_help]' => TRUE,
], 'Save configuration');
$this
->assertRaw('<span class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="Display element description as help text (tooltip)" data-webform-help="<div class="webform-element-help--title">Display element description as help text (tooltip)</div><div class="webform-element-help--content">If checked, all element descriptions will be moved to help text (tooltip).</div>"><span aria-hidden="true">?</span></span>');
$this
->drupalPostForm('/admin/structure/webform/config/advanced', [
'ui[description_help]' => FALSE,
], 'Save configuration');
$this
->assertNoRaw('<span class="webform-element-help js-webform-element-help" role="tooltip" tabindex="0" aria-label="Display element description as help text (tooltip)" data-webform-help="<div class="webform-element-help--title">Display element description as help text (tooltip)</div><div class="webform-element-help--content">If checked, all element descriptions will be moved to help text (tooltip).</div>"><span aria-hidden="true">?</span></span>');
$this
->drupalGet('/admin/structure/webform/config/advanced');
$this
->assertResponse(200);
$this
->assertNoCssSelect('.menu-item a.toolbar-icon-entity-webform-collection');
$this
->drupalPostForm('/admin/structure/webform/config/advanced', [
'ui[toolbar_item]' => TRUE,
], 'Save configuration');
$this
->assertCssSelect('.menu-item a.toolbar-icon-entity-webform-collection');
$this
->drupalGet('/admin/structure/webform/config/advanced');
$this
->assertResponse(404);
$this
->drupalGet('/admin/webform/config/advanced');
$this
->assertResponse(200);
}
protected function ksort(array &$array) {
ksort($array);
foreach ($array as &$value) {
if (is_array($value)) {
ksort($value);
}
}
}
}