diff --git a/core/modules/media/src/Form/EditorMediaDialog.php b/core/modules/media/src/Form/EditorMediaDialog.php index 3eb9b127f0..6530d6d2fe 100644 --- a/core/modules/media/src/Form/EditorMediaDialog.php +++ b/core/modules/media/src/Form/EditorMediaDialog.php @@ -94,6 +94,13 @@ public function buildForm(array $form, FormStateInterface $form_state, EditorInt $form['#prefix'] = '
-
-
-
";
+ $filter_format = $this->container->get('entity_type.manager')->getStorage('filter_format')->load('test_format');
+ $filter_format->setFilterConfig('filter_html', [
+ 'status' => TRUE,
+ 'settings' => [
+ 'allowed_html' => $allowed_html,
+ ],
+ ])->save();
+
+ // Test the validation of attributes in the dialog. If the alt,
+ // data-caption, and data-align attributes are not set on the drupal-media
+ // tag, the respective fields shouldn't display in the dialog.
+ $this->drupalGet($this->host->toUrl('edit-form'));
+ $this->waitForEditor();
+ $this->assignNameToCkeditorIframe();
+ $session->switchToIFrame('ckeditor');
+ $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'drupal-media', 2000));
+ $page->pressButton('Edit media');
+ $this->waitForMetadataDialog();
+ $assert_session->fieldNotExists('attributes[alt]');
+ $assert_session->fieldNotExists('attributes[align]');
+ $assert_session->fieldNotExists('hasCaption');
+ $assert_session->pageTextContains('There is nothing to override for this media.');
+ $page->pressButton('Close');
+ $session->switchToIFrame('ckeditor');
+
+ // Now test that adding the attributes to the allowed HTML will allow
+ // the fields to display in the dialog.
+ $allowed_html = str_replace('', '', $allowed_html);
+ $filter_format->setFilterConfig('filter_html', [
+ 'status' => TRUE,
+ 'settings' => [
+ 'allowed_html' => $allowed_html,
+ ],
+ ])->save();
+ $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'drupal-media', 2000));
+ $page->pressButton('Edit media');
+ $this->waitForMetadataDialog();
+ $assert_session->fieldExists('attributes[alt]');
+ $assert_session->fieldExists('attributes[data-align]');
+ $assert_session->fieldExists('hasCaption');
+ $page->pressButton('Close');
+ $session->switchToIFrame('ckeditor');
+
// Test that setting the media image field to not display alt field also
// disables it in the dialog.
FieldConfig::loadByName('media', 'image', 'field_media_image')
@@ -437,6 +483,49 @@ public function testAlt() {
$page->pressButton('Close');
$session->switchToIFrame('ckeditor');
+ // Test that setting disabling `filter_caption` and `filter_align` disables
+ // the respective fields in the dialog.
+ $filter_format
+ ->setFilterConfig('filter_caption', [
+ 'status' => FALSE,
+ ])->setFilterConfig('filter_align', [
+ 'status' => FALSE,
+ ])->save();
+ // Wait for preview.
+ $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'drupal-media', 2000));
+ $page->pressButton('Edit media');
+ $this->waitForMetadataDialog();
+ $assert_session->fieldNotExists('attributes[data-align]');
+ $assert_session->fieldNotExists('hasCaption');
+ $page->pressButton('Close');
+ $session->switchToIFrame('ckeditor');
+
+ // Test that enabling the two filters restores the fields in the dialog.
+ $filter_format
+ ->setFilterConfig('filter_caption', [
+ 'status' => TRUE,
+ ])->setFilterConfig('filter_align', [
+ 'status' => TRUE,
+ ])->save();
+ // Wait for preview.
+ $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'drupal-media', 2000));
+ $page->pressButton('Edit media');
+ $this->waitForMetadataDialog();
+ $assert_session->fieldExists('attributes[data-align]');
+ $assert_session->fieldExists('hasCaption');
+ }
+
+ /**
+ * Tests the EditorMediaDialog can set the alt attribute.
+ */
+ public function testAlt() {
+ $session = $this->getSession();
+ $page = $session->getPage();
+ $assert_session = $this->assertSession();
+ $this->drupalGet($this->host->toUrl('edit-form'));
+ $this->waitForEditor();
+ $this->assignNameToCkeditorIframe();
+ $session->switchToIFrame('ckeditor');
// Test that the default alt attribute displays without an override.
$this->assertNotEmpty($assert_session->waitForElementVisible('xpath', '//img[contains(@alt, "default alt")]'));
$page->pressButton('Edit media');