View source
<?php
namespace Drupal\Tests\ckeditor_config\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\ckeditor\Traits\CKEditorTestTrait;
class CkeditorConfigTest extends WebDriverTestBase {
use CKEditorTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'ckeditor',
'ckeditor_config',
'editor',
'filter',
'node',
];
protected function setUp() {
parent::setUp();
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => 'Body',
'settings' => [
'display_summary' => TRUE,
],
'required' => TRUE,
])
->save();
EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
])
->setComponent('body', [
'type' => 'text_textarea_with_summary',
])
->save();
$filtered_html_format = FilterFormat::create([
'format' => 'testing_text_format',
'name' => 'Testing Text Format',
'weight' => 0,
'filters' => [],
]);
$filtered_html_format
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'access administration pages',
'administer filters',
'administer nodes',
'create page content',
'use text format testing_text_format',
]));
}
public function testFormSubmission() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet("admin/config/content/formats/manage/testing_text_format");
$page
->fillField('edit-editor-editor', 'ckeditor');
$assert_session
->assertWaitOnAjaxRequest();
$this
->clickLink('CKEditor custom configuration');
$test_value = 'forcePasteAsPlainText = true' . PHP_EOL . 'pasteFromWordPromptCleanup false';
$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.');
$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.');
$editor = editor_load('testing_text_format');
$settings = $editor
->getSettings();
$stored_value = $settings['plugins']['customconfig']['ckeditor_custom_config'];
$stored_value = str_replace([
"\r\n",
"\n",
"\r",
], PHP_EOL, $stored_value);
$this
->assertIdentical($test_value, $stored_value);
$this
->drupalGet('node/add/page');
$this
->waitForEditor();
$settings = $this
->getDrupalSettings();
$settings = $settings['editor']['formats']['testing_text_format']['editorSettings'];
$this
->assertIdentical($settings['forcePasteAsPlainText'], TRUE);
$this
->assertIdentical($settings['pasteFromWordPromptCleanup'], FALSE);
$this
->assertIdentical($settings['removePlugins'], 'font');
$this
->assertIdentical($settings['tabIndex'], 3);
}
}