public function CkeditorConfigTest::testConfigStorage in CKEditor custom config 8.3
Verify settings form validation, submission, and storage.
File
- tests/
src/ FunctionalJavascript/ CkeditorConfigTest.php, line 87
Class
- CkeditorConfigTest
- Verify settings form validation, submission, and storage.
Namespace
Drupal\Tests\ckeditor_config\FunctionalJavascriptCode
public function testConfigStorage() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
// Navigate to configuration page for testing text format.
$this
->drupalGet("admin/config/content/formats/manage/testing_text_format");
$page
->fillField('edit-editor-editor', 'ckeditor');
$assert_session
->assertWaitOnAjaxRequest();
// Enter a value that will fail JSON syntax validation.
$this
->clickLink('CKEditor custom configuration');
$test_value = 'forcePasteAsPlainText = true' . PHP_EOL . 'pasteFromWordPromptCleanup false' . PHP_EOL . 'removePlugins = "font"' . PHP_EOL . 'tabIndex = 3';
$page
->fillField('editor[settings][plugins][customconfig][ckeditor_custom_config]', $test_value);
$page
->pressButton('Save configuration');
$assert_session
->waitForElement('xpath', '//div[@role="alert"]');
$assert_session
->elementTextContains('xpath', '//div[@role="alert"]', 'The configuration syntax on line 2 is incorrect.');
// Enter a value that will pass JSON syntax validation.
$this
->clickLink('CKEditor custom configuration');
$test_value = 'forcePasteAsPlainText = true' . PHP_EOL . 'pasteFromWordPromptCleanup = false' . PHP_EOL . 'removePlugins = "font"' . PHP_EOL . 'tabIndex = 3';
$page
->fillField('editor[settings][plugins][customconfig][ckeditor_custom_config]', $test_value);
$page
->pressButton('Save configuration');
$assert_session
->elementTextContains('xpath', '//div[@aria-label="Status message"]', 'The text format Testing Text Format has been updated.');
$this
->drupalGet("admin/config/content/formats/manage/testing_text_format");
// Enter a value that will fail JSON syntax validation.
$this
->clickLink('CKEditor custom configuration');
$test_value = 'forcePasteAsPlainText = true' . PHP_EOL . 'pasteFromWordPromptCleanup = false' . PHP_EOL . 'removePlugins = "font"' . PHP_EOL . 'tabIndex = 3' . PHP_EOL . 'format_h2 = { element: "h2", attributes: { "class": "contentTitle2" } }';
$page
->fillField('editor[settings][plugins][customconfig][ckeditor_custom_config]', $test_value);
$page
->pressButton('Save configuration');
$assert_session
->waitForElement('xpath', '//div[@role="alert"]');
$assert_session
->elementTextContains('xpath', '//div[@role="alert"]', 'The configuration value on line 5 is not valid JSON.');
// Enter a value that will pass JSON syntax validation.
$this
->clickLink('CKEditor custom configuration');
$test_value = 'forcePasteAsPlainText = true' . PHP_EOL . 'pasteFromWordPromptCleanup = false' . PHP_EOL . 'removePlugins = "font"' . PHP_EOL . 'tabIndex = 3' . PHP_EOL . 'format_h2 = { "element": "h2", "attributes": { "class": "contentTitle2" } }';
$page
->fillField('editor[settings][plugins][customconfig][ckeditor_custom_config]', $test_value);
$page
->pressButton('Save configuration');
$assert_session
->elementTextContains('xpath', '//div[@aria-label="Status message"]', 'The text format Testing Text Format has been updated.');
// Verify submitted value is same as value stored in config.
$editor = editor_load('testing_text_format');
$settings = $editor
->getSettings();
$stored_value = $settings['plugins']['customconfig']['ckeditor_custom_config'];
// Normalize line endings in config value.
$stored_value = str_replace([
"\r\n",
"\n",
"\r",
], PHP_EOL, $stored_value);
$this
->assertIdentical($test_value, $stored_value);
// Verify submitted values are rendered in drupal-settings-json.
$this
->drupalGet('node/add/page');
$this
->waitForEditor();
$settings = $this
->getDrupalSettings();
$settings = $settings['editor']['formats']['testing_text_format']['editorSettings'];
$this
->assertIdentical($settings['forcePasteAsPlainText'], TRUE);
// This value overrides the default value set by the CKEditor's
// Internal plugin.
$this
->assertIdentical($settings['pasteFromWordPromptCleanup'], FALSE);
$this
->assertIdentical($settings['removePlugins'], 'font');
$this
->assertIdentical($settings['tabIndex'], 3);
$test_value = [
'attributes' => [
'class' => 'contentTitle2',
],
'element' => 'h2',
];
$this
->assertIdentical($settings['format_h2'], $test_value);
}