Issue #3078161 by oknate, Meenakshi.g, phenaproxima, Wim Leers: DrupalMediaLibrary plugin breaks things when adding a new text editor

merge-requests/55/head
catch 2019-09-03 14:18:47 +01:00
parent 190f0270c8
commit 9d9fd0ab50
2 changed files with 36 additions and 2 deletions

View File

@ -108,6 +108,14 @@ class DrupalMediaLibrary extends CKEditorPluginBase implements ContainerFactoryP
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
// If the editor has not been saved yet, we may not be able to create a
// coherent MediaLibraryState object, which is needed in order to generate
// the required configuration. But, if we're creating a new editor, we don't
// need to do that anyway, so just return an empty array.
if ($editor->isNew()) {
return [];
}
$media_type_ids = $this->mediaTypeStorage->getQuery()->execute();
if (in_array('image', $media_type_ids, TRUE)) {

View File

@ -122,8 +122,7 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
}
/**
* Tests that media_embed filter is required to enable the DrupalMediaLibrary
* button.
* Tests validation that DrupalMediaLibrary requires media_embed filter.
*/
public function testConfigurationValidation() {
$page = $this->getSession()->getPage();
@ -141,6 +140,33 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
$page->checkField('filters[media_embed][status]');
$page->pressButton('Save configuration');
$assert_session->pageTextContains('The text format Test format has been updated.');
// Now test adding a new format.
$this->drupalGet('/admin/config/content/formats/add');
$page->fillField('name', 'Sulaco');
// Wait for machine name to be filled in.
$this->assertNotEmpty($assert_session->waitForText('sulaco'));
$page->checkField('roles[authenticated]');
$page->selectFieldOption('editor[editor]', 'ckeditor');
$this->assertNotEmpty($target = $assert_session->waitForElementVisible('css', 'ul.ckeditor-toolbar-group-buttons'));
$this->assertNotEmpty($button = $assert_session->elementExists('css', 'li[data-drupal-ckeditor-button-name="DrupalMediaLibrary"]'));
$button->dragTo($target);
$page->pressButton('Save configuration');
$assert_session->pageTextContains('The Embed media filter must be enabled to use the Insert from Media Library button.');
$page->checkField('filters[media_embed][status]');
$page->pressButton('Save configuration');
$assert_session->pageTextContains('Added text format Sulaco.');
// Test that when adding the DrupalMediaLibrary button to the editor the
// correct attributes are added to the <drupal-media> tag in the Allowed
// HTML tags.
$this->drupalGet('/admin/config/content/formats/manage/sulaco');
$page->checkField('filters[filter_html][status]');
$expected = 'drupal-media data-entity-type data-entity-uuid';
$allowed_html = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]')->getValue();
$this->assertContains($expected, $allowed_html);
$page->pressButton('Save configuration');
$assert_session->pageTextContains('The text format Sulaco has been updated.');
}
/**