You are here

class MediaImageTest in Entity Embed 8

Test Media Image specific functionality.

@group entity_embed

Hierarchy

Expanded class hierarchy of MediaImageTest

File

tests/src/FunctionalJavascript/MediaImageTest.php, line 19

Namespace

Drupal\Tests\entity_embed\FunctionalJavascript
View source
class MediaImageTest extends EntityEmbedTestBase {
  use ContentTypeCreationTrait;
  use TestFileCreationTrait;

  /**
   * The user to use during testing.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * The sample Media entity to embed.
   *
   * @var \Drupal\media\MediaInterface
   */
  protected $media;

  /**
   * A host entity with a body field to embed media in.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected $host;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stable';

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    'entity_embed_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Note that media_install() grants 'view media' to all users by default.
    $this->adminUser = $this
      ->drupalCreateUser([
      'use text format full_html',
      'bypass node access',
    ]);
    $this
      ->createNode([
      'type' => 'article',
      'title' => 'Red-lipped batfish',
    ]);

    // Create a sample media entity to be embedded.
    File::create([
      'uri' => $this
        ->getTestFiles('image')[0]->uri,
    ])
      ->save();
    $this->media = Media::create([
      'bundle' => 'image',
      'name' => 'Screaming hairy armadillo',
      'field_media_image' => [
        [
          'target_id' => 1,
          'alt' => 'default alt',
          'title' => 'default title',
        ],
      ],
    ]);
    $this->media
      ->save();

    // Create a sample host entity to embed media in.
    $this
      ->drupalCreateContentType([
      'type' => 'blog',
    ]);
    $this->host = $this
      ->createNode([
      'type' => 'blog',
      'title' => 'Animals with strange names',
      'body' => [
        'value' => '',
        'format' => 'full_html',
      ],
    ]);
    $this->host
      ->save();
    $this
      ->drupalLogin($this->adminUser);
  }

  /**
   * Tests alt and title overriding for embedded images.
   */
  public function testAltAndTitle() {
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->pressEditorButton('test_node');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');

    // Test that node embed doesn't display alt and title fields.
    $this
      ->assertSession()
      ->fieldExists('entity_id')
      ->setValue('Red-lipped batfish (1)');
    $this
      ->assertSession()
      ->elementExists('css', 'button.js-button-next')
      ->click();
    $form = $this
      ->assertSession()
      ->waitForElementVisible('css', 'form.entity-embed-dialog-step--embed');

    // Assert that the review step displays the selected entity with the label.
    $text = $form
      ->getText();
    $this
      ->assertStringContainsString('Red-lipped batfish', $text);
    $select = $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]');
    $select
      ->setValue('view_mode:node.full');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // The view_mode:node.full display shouldn't have alt and title fields.
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');
    $select = $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]');
    $select
      ->setValue('view_mode:node.teaser');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // The view_mode:node.teaser display shouldn't have alt and title fields.
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');

    // Close the dialog.
    $this
      ->assertSession()
      ->elementExists('css', '.ui-dialog-titlebar-close')
      ->press();

    // Now test with media.
    $this
      ->pressEditorButton('test_media_entity_embed');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');
    $this
      ->assertSession()
      ->fieldExists('entity_id')
      ->setValue('Screaming hairy armadillo (1)');
    $this
      ->assertSession()
      ->elementExists('css', 'button.js-button-next')
      ->click();
    $form = $this
      ->assertSession()
      ->waitForElementVisible('css', 'form.entity-embed-dialog-step--embed');

    // Assert that the review step displays the selected entity with the label.
    $text = $form
      ->getText();
    $this
      ->assertStringContainsString('Screaming hairy armadillo', $text);
    $select = $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]');
    $select
      ->setValue('entity_reference:entity_reference_entity_id');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // The entity_reference:entity_reference_entity_id display shouldn't have
    // alt and title fields.
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');
    $select
      ->setValue('entity_reference:entity_reference_label');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // The entity_reference:entity_reference_label display shouldn't have alt
    // and title fields.
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');

    // Test the entity embed display that ships with core media.
    $select
      ->setValue('entity_reference:media_thumbnail');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]')
      ->setValue('view_mode:media.embed');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $alt = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertEquals($this->media->field_media_image->alt, $alt
      ->getAttribute('placeholder'));
    $title = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]');
    $this
      ->assertEquals($this->media->field_media_image->title, $title
      ->getAttribute('placeholder'));
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals("default alt", $img
      ->getAttribute('alt'));
    $this
      ->assertEquals("default title", $img
      ->getAttribute('title'));
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]')
      ->setValue('Satanic leaf-tailed gecko alt');
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]')
      ->setValue('Satanic leaf-tailed gecko title');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals("Satanic leaf-tailed gecko alt", $img
      ->getAttribute('alt'));
    $this
      ->assertEquals("Satanic leaf-tailed gecko title", $img
      ->getAttribute('title'));
    $this
      ->reopenDialog();

    // Test a view mode that displays thumbnail field.
    $select
      ->setValue('view_mode:media.thumb');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]')
      ->setValue('view_mode:media.embed');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $alt = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertEquals('Satanic leaf-tailed gecko alt', $alt
      ->getValue());
    $title = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]');
    $this
      ->assertEquals('Satanic leaf-tailed gecko title', $title
      ->getValue());
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('Satanic leaf-tailed gecko alt', $img
      ->getAttribute('alt'));
    $this
      ->assertEquals('Satanic leaf-tailed gecko title', $img
      ->getAttribute('title'));
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]')
      ->setValue('Goblin shark alt');
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]')
      ->setValue('Goblin shark title');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals("Goblin shark alt", $img
      ->getAttribute('alt'));
    $this
      ->assertEquals("Goblin shark title", $img
      ->getAttribute('title'));
    $this
      ->reopenDialog();

    // Test a view mode that displays the media's image field.
    $select
      ->setValue('view_mode:media.embed');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // Test that the view_mode:media.embed display has alt and title fields,
    // and that the default values match the values on the media's
    // source image field.
    $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]')
      ->setValue('view_mode:media.embed');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $alt = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertEquals("Goblin shark alt", $alt
      ->getValue());
    $title = $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]');
    $this
      ->assertEquals("Goblin shark title", $title
      ->getValue());
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals("Goblin shark alt", $img
      ->getAttribute('alt'));
    $this
      ->assertEquals("Goblin shark title", $img
      ->getAttribute('title'));
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]')
      ->setValue('Satanic leaf-tailed gecko alt');
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]')
      ->setValue('Satanic leaf-tailed gecko title');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('Satanic leaf-tailed gecko alt', $img
      ->getAttribute('alt'));
    $this
      ->assertEquals('Satanic leaf-tailed gecko title', $img
      ->getAttribute('title'));
    $this
      ->config('field.field.media.image.field_media_image')
      ->set('settings.alt_field', FALSE)
      ->set('settings.title_field', FALSE)
      ->save();
    drupal_flush_all_caches();
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('default alt', $img
      ->getAttribute('alt'));
    $this
      ->assertEquals('default title', $img
      ->getAttribute('title'));
    $field = FieldConfig::load('media.image.field_media_image');
    $settings = $field
      ->getSettings();
    $settings['alt_field'] = TRUE;
    $field
      ->set('settings', $settings);
    $field
      ->save();
    drupal_flush_all_caches();
    $this
      ->reopenDialog();

    // Test that when only the alt field is enabled, only alt field should
    // display.
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][alt]')
      ->setValue('Satanic leaf-tailed gecko alt');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][title]');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('Satanic leaf-tailed gecko alt', $img
      ->getAttribute('alt'));
    $this
      ->assertEquals('default title', $img
      ->getAttribute('title'));
    $field = FieldConfig::load('media.image.field_media_image');
    $settings = $field
      ->getSettings();
    $settings['alt_field'] = FALSE;
    $settings['title_field'] = TRUE;
    $field
      ->set('settings', $settings);
    $field
      ->save();
    drupal_flush_all_caches();
    $this
      ->reopenDialog();

    // With only title field enabled, only title field should display.
    $this
      ->assertSession()
      ->fieldExists('attributes[data-entity-embed-display-settings][title]')
      ->setValue('Satanic leaf-tailed gecko title');
    $this
      ->assertSession()
      ->fieldNotExists('attributes[data-entity-embed-display-settings][alt]');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('Satanic leaf-tailed gecko title', $img
      ->getAttribute('title'));
    $this
      ->assertEquals('default alt', $img
      ->getAttribute('alt'));
    $field = FieldConfig::load('media.image.field_media_image');
    $settings = $field
      ->getSettings();
    $settings['alt_field'] = TRUE;
    $settings['title_field'] = TRUE;
    $field
      ->set('settings', $settings);
    $field
      ->save();
    drupal_flush_all_caches();
    $this
      ->reopenDialog();

    // Test that setting value to double quote will allow setting the alt
    // and title to empty.
    $alt
      ->setValue(MediaImageDecorator::EMPTY_STRING);
    $title
      ->setValue(MediaImageDecorator::EMPTY_STRING);
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEmpty($img
      ->getAttribute('alt'));
    $this
      ->assertEmpty($img
      ->getAttribute('title'));
    $this
      ->reopenDialog();

    // Test that *not* filling out the fields makes it fall back to the default.
    $alt
      ->setValue('');
    $title
      ->setValue('');
    $this
      ->submitDialog();
    $img = $this
      ->assertSession()
      ->elementExists('css', 'img');
    $this
      ->assertEquals('default alt', $img
      ->getAttribute('alt'));
    $this
      ->assertEquals('default title', $img
      ->getAttribute('title'));
  }

  /**
   * Tests caption editing in the CKEditor widget.
   */
  public function testCkeditorWidgetHasEditableCaption() {
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->pressEditorButton('test_media_entity_embed');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');

    // Embed media.
    $this
      ->assertSession()
      ->fieldExists('entity_id')
      ->setValue('Screaming hairy armadillo (1)');
    $this
      ->assertSession()
      ->elementExists('css', 'button.js-button-next')
      ->click();
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'form.entity-embed-dialog-step--embed');
    $this
      ->assertSession()
      ->selectExists('attributes[data-entity-embed-display]')
      ->setValue('entity_reference:media_thumbnail');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-caption]')
      ->setValue('Is this the real life? Is this just fantasy?');
    $this
      ->submitDialog();

    // Assert that the embedded media was upcasted to a CKEditor widget.
    $figcaption = $this
      ->assertSession()
      ->elementExists('css', 'figcaption');
    $this
      ->assertTrue($figcaption
      ->hasAttribute('contenteditable'));

    // Type in the widget's editable for the caption.
    $this
      ->assertSession()
      ->waitForElement('css', 'figcaption');
    $this
      ->setCaption('Caught in a <strong>landslide</strong>! No escape from <em>reality</em>!');
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementExists('css', 'figcaption > em');
    $this
      ->assertSession()
      ->elementExists('css', 'figcaption > strong')
      ->click();

    // Select the <strong> element and unbold it.
    $this
      ->clickPathLinkByTitleAttribute("strong element");
    $this
      ->pressEditorButton('bold');
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementExists('css', 'figcaption > em');
    $this
      ->assertSession()
      ->elementNotExists('css', 'figcaption > strong');

    // Select the <em> element and unitalicize it.
    $this
      ->assertSession()
      ->elementExists('css', 'figcaption > em')
      ->click();
    $this
      ->clickPathLinkByTitleAttribute("em element");
    $this
      ->pressEditorButton('italic');

    // The "source" button should reveal the HTML source in a state matching
    // what is shown in the CKEditor widget.
    $this
      ->pressEditorButton('source');
    $source = $this
      ->assertSession()
      ->elementExists('css', 'textarea.cke_source');
    $value = $source
      ->getValue();
    $dom = Html::load($value);
    $xpath = new \DOMXPath($dom);
    $drupal_entity = $xpath
      ->query('//drupal-entity')[0];
    $this
      ->assertEquals('Caught in a landslide! No escape from reality!', $drupal_entity
      ->getAttribute('data-caption'));

    // Change the caption by modifying the HTML source directly. When exiting
    // "source" mode, this should be respected.
    $poor_boy_text = "I'm just a <strong>poor boy</strong>, I need no sympathy!";
    $drupal_entity
      ->setAttribute("data-caption", $poor_boy_text);
    $source
      ->setValue(Html::serialize($dom));
    $this
      ->pressEditorButton('source');
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $figcaption = $this
      ->assertSession()
      ->waitForElement('css', 'figcaption');
    $this
      ->assertEquals($poor_boy_text, $figcaption
      ->getHtml());

    // Select the <strong> element that we just set in "source" mode. This
    // proves that it was indeed rendered by the CKEditor widget.
    $figcaption
      ->find('css', 'strong')
      ->click();
    $this
      ->pressEditorButton('bold');

    // Insert a link into the caption.
    $this
      ->clickPathLinkByTitleAttribute("Caption element");
    $this
      ->pressEditorButton('drupallink');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');
    $this
      ->assertSession()
      ->waitForElementVisible('css', '#editor-link-dialog-form')
      ->findField('attributes[href]')
      ->setValue('https://www.drupal.org');
    $this
      ->assertSession()
      ->elementExists('css', 'button.form-submit')
      ->press();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // Wait for the live preview in the CKEditor widget to finish loading, then
    // edit the link; no `data-cke-saved-href` attribute should exist on it.
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $figcaption = $this
      ->assertSession()
      ->waitForElement('css', 'figcaption');
    $figcaption
      ->find('css', 'a')
      ->click();
    $this
      ->clickPathLinkByTitleAttribute("a element");
    $this
      ->pressEditorButton('drupallink');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');
    $this
      ->assertSession()
      ->waitForElementVisible('css', '#editor-link-dialog-form')
      ->findField('attributes[href]')
      ->setValue('https://www.drupal.org/project/drupal');
    $this
      ->assertSession()
      ->elementExists('css', 'button.form-submit')
      ->press();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->pressEditorButton('source');
    $source = $this
      ->assertSession()
      ->elementExists('css', "textarea.cke_source");
    $value = $source
      ->getValue();
    $this
      ->assertStringContainsString('https://www.drupal.org/project/drupal', $value);
    $this
      ->assertStringNotContainsString('data-cke-saved-href', $value);

    // Save the entity.
    $this
      ->assertSession()
      ->buttonExists('Save')
      ->press();

    // Verify the saved entity when viewed also contains the captioned media.
    $link = $this
      ->assertSession()
      ->elementExists('css', 'figcaption > a');
    $this
      ->assertEquals('https://www.drupal.org/project/drupal', $link
      ->getAttribute('href'));
    $this
      ->assertEquals("I'm just a poor boy, I need no sympathy!", $link
      ->getText());

    // Edit it again, type a different caption in the widget.
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'figcaption');
    $this
      ->setCaption('Scaramouch, <em>Scaramouch</em>, will you do the <strong>Fandango</strong>?');

    // Verify that the element path usefully indicates the specific media type
    // that is being embedded.
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementExists('xpath', '//figcaption//em')
      ->click();
    $this
      ->getSession()
      ->switchToIFrame();
    $this
      ->assertSession()
      ->elementTextContains('css', '#cke_1_path', 'Embedded Media Entity Embed');

    // Test that removing caption in the EntityEmbedDialog form sets the embed
    // to be captionless.
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-caption]')
      ->setValue('');
    $this
      ->submitDialog();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->assertSession()
      ->elementExists('css', 'drupal-entity');
    $this
      ->assertSession()
      ->elementNotExists('css', 'figcaption');

    // Set a caption again; this time not using the CKEditor Widget, but through
    // the dialog. We're typing HTML in the form field, but it will have to be
    // HTML-encoded for it to actually show up properly in the CKEditor Widget.
    $this
      ->reopenDialog();
    $freddys_lament = "Mama, life had just begun. But now I've gone and <strong>thrown it all away</strong>! :(";
    $this
      ->assertSession()
      ->fieldExists('attributes[data-caption]')
      ->setValue($freddys_lament);
    $this
      ->submitDialog();
    $this
      ->assertSession()
      ->elementExists('css', 'figcaption');

    // Change the caption in the dialog to contain a link.
    $wind_markup = '<a href="http://www.drupal.org">anyway the wind blows</a>';
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-caption]')
      ->setValue($wind_markup);
    $this
      ->submitDialog();

    // Assert the caption in the CKEditor widget was updated.
    $figcaption = $this
      ->assertSession()
      ->waitForElementVisible('css', 'figcaption');
    $this
      ->assertEquals('anyway the wind blows', $figcaption
      ->getText());

    // Change the text of the link in the caption.
    $gallileo = '<a href="http://www.drupal.org">Gallileo, figaro, magnifico</a>';
    $this
      ->reopenDialog();
    $this
      ->assertSession()
      ->fieldExists('attributes[data-caption]')
      ->setValue($gallileo);
    $this
      ->submitDialog();

    // Assert the caption in the CKEditor widget was updated.
    $figcaption = $this
      ->assertSession()
      ->waitForElementVisible('css', 'figcaption');
    $this
      ->assertEquals('Gallileo, figaro, magnifico', $figcaption
      ->getText());

    // Erase the caption in the CKEditor Widget, verify the <figcaption> still
    // exists and contains placeholder text, then type something else.
    $this
      ->setCaption('');
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementContains('css', 'figcaption', '');
    $this
      ->assertSession()
      ->elementAttributeContains('css', 'figcaption', 'data-placeholder', 'Enter caption here');
    $this
      ->setCaption('Fin.');
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementContains('css', 'figcaption', 'Fin.');
  }

  /**
   * Tests linkability of the CKEditor widget when `drupalimage` is disabled.
   */
  public function testCkeditorWidgetIsLinkableWhenDrupalImageIsAbsent() {

    // Remove the `drupalimage` plugin's `DrupalImage` button.
    $editor = Editor::load('full_html');
    $settings = $editor
      ->getSettings();
    $rows = $settings['toolbar']['rows'];
    foreach ($rows as $row_key => $row) {
      foreach ($row as $group_key => $group) {
        foreach ($group['items'] as $item_key => $item) {
          if ($item === 'DrupalImage') {
            unset($settings['toolbar']['rows'][$row_key][$group_key]['items'][$item_key]);
          }
        }
      }
    }
    $editor
      ->setSettings($settings);
    $editor
      ->save();
    $this
      ->testCkeditorWidgetIsLinkable();
  }

  /**
   * Tests linkability of the CKEditor widget.
   */
  public function testCkeditorWidgetIsLinkable() {
    $this->host->body->value = '<drupal-entity data-caption="baz" data-embed-button="test_media_entity_embed" data-entity-embed-display="entity_reference:media_thumbnail" data-entity-embed-display-settings="{&quot;image_style&quot;:&quot;&quot;,&quot;image_link&quot;:&quot;&quot;}" data-entity-type="media" data-entity-uuid="' . $this->media
      ->uuid() . '"></drupal-entity>';
    $this->host
      ->save();
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');

    // Select the CKEditor Widget and click the "link" button.
    $drupal_entity = $this
      ->assertSession()
      ->waitForElementVisible('css', 'drupal-entity');
    $this
      ->assertNotEmpty($drupal_entity);
    $drupal_entity
      ->click();
    $this
      ->pressEditorButton('drupallink');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');

    // Enter a link in the link dialog and save.
    $this
      ->assertSession()
      ->waitForElementVisible('css', '#editor-link-dialog-form')
      ->findField('attributes[href]')
      ->setValue('https://www.drupal.org');
    $this
      ->assertSession()
      ->elementExists('css', 'button.form-submit')
      ->press();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();

    // Save the entity.
    $this
      ->assertSession()
      ->buttonExists('Save')
      ->press();

    // Verify the saved entity when viewed also contains the linked media.
    $this
      ->assertSession()
      ->elementExists('css', 'figure > a[href="https://www.drupal.org"] > div[data-embed-button="test_media_entity_embed"] > img[src*="image-test.png"]');

    // Test that `drupallink` also still works independently: inserting a link
    // is possible.
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->pressEditorButton('drupallink');
    $this
      ->assertSession()
      ->waitForId('drupal-modal');
    $this
      ->assertSession()
      ->waitForElementVisible('css', '#editor-link-dialog-form')
      ->findField('attributes[href]')
      ->setValue('https://wikipedia.org');
    $this
      ->assertSession()
      ->elementExists('css', 'button.form-submit')
      ->press();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->elementExists('css', 'body > a[href="https://wikipedia.org"]');
    $this
      ->assertSession()
      ->elementExists('css', 'body > .cke_widget_drupalentity > drupal-entity > figure > a[href="https://www.drupal.org"]');
  }

  /**
   * Tests that only <drupal-entity> tags are processed.
   *
   * @see \Drupal\Tests\entity_embed\Kernel\EntityEmbedFilterTest::testOnlyDrupalEntityTagProcessed()
   */
  public function testOnlyDrupalEntityTagProcessed() {
    $embed_code = '<drupal-entity data-caption="baz" data-embed-button="test_media_entity_embed" data-entity-embed-display="entity_reference:media_thumbnail" data-entity-embed-display-settings="{&quot;image_style&quot;:&quot;&quot;,&quot;image_link&quot;:&quot;&quot;}" data-entity-type="media" data-entity-uuid="' . $this->media
      ->uuid() . '"></drupal-entity>';
    $this->host->body->value = str_replace('drupal-entity', 'p', $embed_code);
    $this->host
      ->save();

    // Assert that `<p data-* …>` is not upcast into a CKEditor Widget.
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'img[src*="example.jpg"]', 1000);
    $this
      ->assertSession()
      ->elementNotExists('css', 'figure');
    $this->host->body->value = $embed_code;
    $this->host
      ->save();

    // Assert that `<drupal-entity data-* …>` is upcast into a CKEditor Widget.
    $this
      ->getSession()
      ->reload();
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'img[src*="example.jpg"]');
    $this
      ->assertSession()
      ->elementExists('css', 'figure');
  }

  /**
   * The CKEditor Widget must load a preview generated using the default theme.
   */
  public function testPreviewUsesDefaultThemeAndIsClientCacheable() {

    // Make the node edit form use the admin theme, like on most Drupal sites.
    $this
      ->config('node.settings')
      ->set('use_admin_theme', TRUE)
      ->save();
    $this->container
      ->get('router.builder')
      ->rebuild();

    // Allow the test user to view the admin theme.
    $this->adminUser
      ->addRole($this
      ->drupalCreateRole([
      'view the administration theme',
    ]));
    $this->adminUser
      ->save();

    // Configure a different default and admin theme, like on most Drupal sites.
    $this
      ->config('system.theme')
      ->set('default', 'stable')
      ->set('admin', 'classy')
      ->save();

    // Assert that when looking at an embedded entity in the CKEditor Widget,
    // the preview is generated using the default theme, not the admin theme.
    // @see entity_embed_test_entity_view_alter()
    $this->host->body->value = '<drupal-entity data-caption="baz" data-embed-button="test_media_entity_embed" data-entity-embed-display="entity_reference:entity_reference_entity_view" data-entity-embed-display-settings="full" data-entity-type="media" data-entity-uuid="' . $this->media
      ->uuid() . '"></drupal-entity>';
    $this->host
      ->save();
    $this
      ->drupalGet($this->host
      ->toUrl('edit-form'));
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'img[src*="image-test.png"]');
    $element = $this
      ->assertSession()
      ->elementExists('css', '[data-entity-embed-test-active-theme]');
    $this
      ->assertSame('stable', $element
      ->getAttribute('data-entity-embed-test-active-theme'));

    // Assert that the first preview request transferred data over the wire.
    // Then toggle source mode on and off. This causes the CKEditor widget to be
    // destroyed and then reconstructed. Assert that during this reconstruction,
    // a second request is sent. This second request should have transferred 0
    // bytes: the browser should have cached the response, thus resulting in a
    // much better user experience.
    $this
      ->assertGreaterThan(0, $this
      ->getLastPreviewRequestTransferSize());
    $this
      ->pressEditorButton('source');
    $this
      ->assertSession()
      ->waitForElement('css', 'textarea.cke_source');
    $this
      ->pressEditorButton('source');
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertSession()
      ->waitForElementVisible('css', 'img[src*="image-test.png"]');
    $this
      ->assertSame(0, $this
      ->getLastPreviewRequestTransferSize());
  }

  /**
   * Gets the transfer size of the last preview request.
   *
   * @return int
   *   The transfer size in octets.
   */
  protected function getLastPreviewRequestTransferSize() {
    $this
      ->getSession()
      ->switchToIFrame();
    $javascript = <<<JS
(function(){
  return window.performance
    .getEntries()
    .filter(function (entry) {
      return entry.initiatorType == 'xmlhttprequest' && entry.name.indexOf('/entity-embed/preview/') !== -1;
    })
    .pop()
    .transferSize;
})()
JS;
    return $this
      ->getSession()
      ->evaluateScript($javascript);
  }

  /**
   * Tests even <drupal-entity> elements whose button is not present are upcast.
   *
   * @param string $data_embed_button_attribute
   *   The HTML for a data-embed-button atttribute.
   *
   * @dataProvider providerCkeditorWidgetWorksForAllEmbeds
   */
  public function testCkeditorWidgetWorksForAllEmbeds($data_embed_button_attribute) {
    $this->host->body->value = '<drupal-entity data-caption="baz" ' . $data_embed_button_attribute . ' data-entity-embed-display="entity_reference:media_thumbnail" data-entity-embed-display-settings="{&quot;image_style&quot;:&quot;&quot;,&quot;image_link&quot;:&quot;&quot;}" data-entity-type="media" data-entity-uuid="' . $this->media
      ->uuid() . '"></drupal-entity>';
    $this->host
      ->save();
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('node/' . $this->host
      ->id() . '/edit');
    $this
      ->waitForEditor();
    $this
      ->assignNameToCkeditorIframe();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
    $this
      ->assertNotNull($this
      ->assertSession()
      ->waitForElementVisible('css', 'figcaption'));
  }

  /**
   * Data provider for testCkeditorWidgetWorksForAllEmbeds().
   */
  public function providerCkeditorWidgetWorksForAllEmbeds() {
    return [
      'present and active CKEditor button ID' => [
        'data-embed-button="test_media_entity_embed"',
      ],
      'present and inactive CKEditor button ID' => [
        'data-embed-button="user"',
      ],
      'present and nonsensical CKEditor button ID' => [
        'data-embed-button="ceci nest pas une pipe"',
      ],
      'absent' => [
        '',
      ],
    ];
  }

  /**
   * Helper function to submit dialog and focus on ckeditor frame.
   */
  protected function submitDialog() {
    $this
      ->assertSession()
      ->elementExists('css', 'button.button--primary')
      ->press();
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->getSession()
      ->switchToIFrame('ckeditor');
  }

  /**
   * Set the text of the editable caption to the given text.
   *
   * @param string $text
   *   The text to set in the caption.
   */
  protected function setCaption($text) {
    $this
      ->getSession()
      ->switchToIFrame();
    $select_and_edit_caption = "var editor = CKEDITOR.instances['edit-body-0-value'];\n       var figcaption = editor.widgets.getByElement(editor.editable().findOne('figcaption'));\n       figcaption.editables.caption.setData('" . $text . "')";
    $this
      ->getSession()
      ->executeScript($select_and_edit_caption);
  }

  /**
   * Clicks a link in the editor's path links with the given title text.
   *
   * @param string $text
   *   The title attribute of the link to click.
   *
   * @throws \Behat\Mink\Exception\ElementNotFoundException
   */
  protected function clickPathLinkByTitleAttribute($text) {
    $this
      ->getSession()
      ->switchToIFrame();
    $selector = '//span[@id="cke_1_path"]//a[@title="' . $text . '"]';
    $this
      ->assertSession()
      ->elementExists('xpath', $selector)
      ->click();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertCacheTag protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertLink protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw protected function Passes if the raw text IS not found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text. 1
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertResponse protected function Asserts the page responds with the specified response code. 1
AssertLegacyTrait::assertText protected function Passes if the page (with HTML stripped) contains the text. 1
AssertLegacyTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent protected function Gets the current raw content.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
BlockCreationTrait::placeBlock protected function Creates a block instance based on default settings. Aliased as: drupalPlaceBlock
BrowserHtmlDebugTrait::$htmlOutputBaseUrl protected property The Base URI to use for links to the output files.
BrowserHtmlDebugTrait::$htmlOutputClassName protected property Class name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounter protected property Counter for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounterStorage protected property Counter storage for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputDirectory protected property Directory name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputEnabled protected property HTML output output enabled.
BrowserHtmlDebugTrait::$htmlOutputFile protected property The file name to write the list of URLs to.
BrowserHtmlDebugTrait::$htmlOutputTestId protected property HTML output test ID.
BrowserHtmlDebugTrait::formatHtmlOutputHeaders protected function Formats HTTP headers as string for HTML output logging.
BrowserHtmlDebugTrait::htmlOutput protected function Logs a HTML output message in a text file.
BrowserHtmlDebugTrait::initBrowserOutputFile protected function Creates the directory to store browser output.
BrowserTestBase::$baseUrl protected property The base URL.
BrowserTestBase::$configImporter protected property The config importer that can be used in a test.
BrowserTestBase::$customTranslations protected property An array of custom translations suitable for drupal_rewrite_settings().
BrowserTestBase::$databasePrefix protected property The database prefix of this test run.
BrowserTestBase::$mink protected property Mink session manager.
BrowserTestBase::$minkDefaultDriverArgs protected property
BrowserTestBase::$originalContainer protected property The original container.
BrowserTestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks.
BrowserTestBase::$preserveGlobalState protected property
BrowserTestBase::$profile protected property The profile to install as a basis for testing. 39
BrowserTestBase::$root protected property The app root.
BrowserTestBase::$runTestInSeparateProcess protected property Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests.
BrowserTestBase::$timeLimit protected property Time limit in seconds for the test.
BrowserTestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
BrowserTestBase::cleanupEnvironment protected function Clean up the Simpletest environment.
BrowserTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
BrowserTestBase::cssSelectToXpath protected function Translates a CSS expression to its XPath equivalent.
BrowserTestBase::drupalGetHeader protected function Gets the value of an HTTP response header.
BrowserTestBase::drupalGetHeaders Deprecated protected function Returns all response headers.
BrowserTestBase::filePreDeleteCallback public static function Ensures test files are deletable.
BrowserTestBase::getDefaultDriverInstance protected function Gets an instance of the default Mink driver.
BrowserTestBase::getHttpClient protected function Obtain the HTTP client for the system under test.
BrowserTestBase::getOptions protected function Helper function to get the options of select field.
BrowserTestBase::getResponseLogHandler protected function Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait::getResponseLogHandler
BrowserTestBase::getSession public function Returns Mink session.
BrowserTestBase::getSessionCookies protected function Get session cookies from current session.
BrowserTestBase::getTestMethodCaller protected function Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait::getTestMethodCaller
BrowserTestBase::installDrupal public function Installs Drupal into the Simpletest site. 1
BrowserTestBase::registerSessions protected function Registers additional Mink sessions.
BrowserTestBase::translatePostValues protected function Transforms a nested array into a flat array suitable for drupalPostForm().
BrowserTestBase::xpath protected function Performs an xpath search on the contents of the internal browser.
BrowserTestBase::__construct public function 1
BrowserTestBase::__sleep public function Prevents serializing any properties.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. 1
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType 1
EntityEmbedTestBase::assignNameToCkeditorIframe protected function Assigns a name to the CKEditor iframe, to allow use of ::switchToIFrame().
EntityEmbedTestBase::pressEditorButton protected function Clicks a CKEditor button.
EntityEmbedTestBase::reopenDialog protected function Helper function to reopen EntityEmbedDialog for first embed.
EntityEmbedTestBase::showHiddenFields protected function Show visually hidden fields.
EntityEmbedTestBase::waitForEditor protected function Waits for CKEditor to initialize.
FunctionalTestSetupTrait::$apcuEnsureUniquePrefix protected property The flag to set 'apcu_ensure_unique_prefix' setting. 1
FunctionalTestSetupTrait::$classLoader protected property The class loader to use for installation and initialization of setup.
FunctionalTestSetupTrait::$configDirectories Deprecated protected property The config directories used in this test.
FunctionalTestSetupTrait::$rootUser protected property The "#1" admin user.
FunctionalTestSetupTrait::doInstall protected function Execute the non-interactive installer. 1
FunctionalTestSetupTrait::getDatabaseTypes protected function Returns all supported database driver installer objects.
FunctionalTestSetupTrait::initConfig protected function Initialize various configurations post-installation. 2
FunctionalTestSetupTrait::initKernel protected function Initializes the kernel after installation.
FunctionalTestSetupTrait::initSettings protected function Initialize settings created during install.
FunctionalTestSetupTrait::initUserSession protected function Initializes user 1 for the site to be installed.
FunctionalTestSetupTrait::installDefaultThemeFromClassProperty protected function Installs the default theme defined by `static::$defaultTheme` when needed.
FunctionalTestSetupTrait::installParameters protected function Returns the parameters that will be used when Simpletest installs Drupal. 9
FunctionalTestSetupTrait::prepareEnvironment protected function Prepares the current environment for running the test. 23
FunctionalTestSetupTrait::prepareRequestForGenerator protected function Creates a mock request and sets it on the generator.
FunctionalTestSetupTrait::prepareSettings protected function Prepares site settings and services before installation. 2
FunctionalTestSetupTrait::rebuildAll protected function Resets and rebuilds the environment after setup.
FunctionalTestSetupTrait::rebuildContainer protected function Rebuilds \Drupal::getContainer().
FunctionalTestSetupTrait::resetAll protected function Resets all data structures after having enabled new modules.
FunctionalTestSetupTrait::setContainerParameter protected function Changes parameters in the services.yml file.
FunctionalTestSetupTrait::setupBaseUrl protected function Sets up the base URL based upon the environment variable.
FunctionalTestSetupTrait::writeSettings protected function Rewrites the settings.php file of the test site.
MediaImageTest::$adminUser protected property The user to use during testing.
MediaImageTest::$defaultTheme protected property The theme to install as the default for testing. Overrides EntityEmbedTestBase::$defaultTheme
MediaImageTest::$host protected property A host entity with a body field to embed media in.
MediaImageTest::$media protected property The sample Media entity to embed.
MediaImageTest::$modules public static property Modules to enable. Overrides EntityEmbedTestBase::$modules
MediaImageTest::clickPathLinkByTitleAttribute protected function Clicks a link in the editor's path links with the given title text.
MediaImageTest::getLastPreviewRequestTransferSize protected function Gets the transfer size of the last preview request.
MediaImageTest::providerCkeditorWidgetWorksForAllEmbeds public function Data provider for testCkeditorWidgetWorksForAllEmbeds().
MediaImageTest::setCaption protected function Set the text of the editable caption to the given text.
MediaImageTest::setUp protected function Overrides BrowserTestBase::setUp
MediaImageTest::submitDialog protected function Helper function to submit dialog and focus on ckeditor frame.
MediaImageTest::testAltAndTitle public function Tests alt and title overriding for embedded images.
MediaImageTest::testCkeditorWidgetHasEditableCaption public function Tests caption editing in the CKEditor widget.
MediaImageTest::testCkeditorWidgetIsLinkable public function Tests linkability of the CKEditor widget.
MediaImageTest::testCkeditorWidgetIsLinkableWhenDrupalImageIsAbsent public function Tests linkability of the CKEditor widget when `drupalimage` is disabled.
MediaImageTest::testCkeditorWidgetWorksForAllEmbeds public function Tests even <drupal-entity> elements whose button is not present are upcast.
MediaImageTest::testOnlyDrupalEntityTagProcessed public function Tests that only <drupal-entity> tags are processed.
MediaImageTest::testPreviewUsesDefaultThemeAndIsClientCacheable public function The CKEditor Widget must load a preview generated using the default theme.
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 3
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestFileCreationTrait::$generatedTestFiles protected property Whether the files were copied to the test files directory.
TestFileCreationTrait::compareFiles protected function Compares two files based on size and file name.
TestFileCreationTrait::generateFile public static function Generates a test file.
TestFileCreationTrait::getTestFiles protected function Gets a list of files that can be used in tests.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
TestSetupTrait::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestSetupTrait::$container protected property The dependency injection container used in the test.
TestSetupTrait::$kernel protected property The DrupalKernel instance used in the test.
TestSetupTrait::$originalSite protected property The site directory of the original parent site.
TestSetupTrait::$privateFilesDirectory protected property The private file directory for the test environment.
TestSetupTrait::$publicFilesDirectory protected property The public file directory for the test environment.
TestSetupTrait::$siteDirectory protected property The site directory of this test run.
TestSetupTrait::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 2
TestSetupTrait::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestSetupTrait::$testId protected property The test run ID.
TestSetupTrait::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestSetupTrait::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestSetupTrait::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestSetupTrait::prepareDatabasePrefix protected function Generates a database prefix for running tests. 2
UiHelperTrait::$loggedInUser protected property The current user logged in using the Mink controlled browser.
UiHelperTrait::$maximumMetaRefreshCount protected property The number of meta refresh redirects to follow, or NULL if unlimited.
UiHelperTrait::$metaRefreshCount protected property The number of meta refresh redirects followed during ::drupalGet().
UiHelperTrait::buildUrl protected function Builds an a absolute URL from a system path or a URL object.
UiHelperTrait::checkForMetaRefresh protected function Checks for meta refresh tag and if found call drupalGet() recursively.
UiHelperTrait::click protected function Clicks the element with the given CSS selector.
UiHelperTrait::clickLink protected function Follows a link by complete name.
UiHelperTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
UiHelperTrait::drupalGet protected function Retrieves a Drupal path or an absolute path. 3
UiHelperTrait::drupalLogin protected function Logs in a user using the Mink controlled browser.
UiHelperTrait::drupalLogout protected function Logs a user out of the Mink controlled browser and confirms.
UiHelperTrait::drupalPostForm protected function Executes a form submission.
UiHelperTrait::drupalUserIsLoggedIn protected function Returns whether a given user account is logged in.
UiHelperTrait::getAbsoluteUrl protected function Takes a path and returns an absolute path.
UiHelperTrait::getTextContent protected function Retrieves the plain-text content from the current page.
UiHelperTrait::getUrl protected function Get the current URL from the browser.
UiHelperTrait::prepareRequest protected function Prepare for a request to testing site. 1
UiHelperTrait::submitForm protected function Fills and submits a form.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
WebDriverTestBase::$disableCssAnimations protected property Disables CSS animations in tests for more reliable testing.
WebDriverTestBase::$minkDefaultDriverClass protected property To use a legacy phantomjs based approach, please use PhantomJSDriver::class. Overrides BrowserTestBase::$minkDefaultDriverClass 2
WebDriverTestBase::assertElementNotVisible Deprecated protected function Asserts that the element with the given CSS selector is not visible.
WebDriverTestBase::assertElementVisible Deprecated protected function Asserts that the element with the given CSS selector is visible.
WebDriverTestBase::assertJsCondition protected function Waits for the given time or until the given JS condition becomes TRUE.
WebDriverTestBase::assertSession public function Returns WebAssert object. Overrides UiHelperTrait::assertSession 1
WebDriverTestBase::createScreenshot protected function Creates a screenshot.
WebDriverTestBase::getDrupalSettings protected function Gets the current Drupal javascript settings and parses into an array. Overrides BrowserTestBase::getDrupalSettings
WebDriverTestBase::getHtmlOutputHeaders protected function Returns headers in HTML output format. Overrides BrowserHtmlDebugTrait::getHtmlOutputHeaders
WebDriverTestBase::getMinkDriverArgs protected function Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. Overrides BrowserTestBase::getMinkDriverArgs
WebDriverTestBase::initFrontPage protected function Visits the front page when initializing Mink. Overrides BrowserTestBase::initFrontPage
WebDriverTestBase::initMink protected function Initializes Mink sessions. Overrides BrowserTestBase::initMink 1
WebDriverTestBase::installModulesFromClassProperty protected function Install modules defined by `static::$modules`. Overrides FunctionalTestSetupTrait::installModulesFromClassProperty
WebDriverTestBase::tearDown protected function Overrides BrowserTestBase::tearDown 1
XdebugRequestTrait::extractCookiesFromRequest protected function Adds xdebug cookies, from request setup.