public function MediaImageTest::testCkeditorWidgetIsLinkable in Entity Embed 8
Tests linkability of the CKEditor widget.
1 call to MediaImageTest::testCkeditorWidgetIsLinkable()
- MediaImageTest::testCkeditorWidgetIsLinkableWhenDrupalImageIsAbsent in tests/
src/ FunctionalJavascript/ MediaImageTest.php  - Tests linkability of the CKEditor widget when `drupalimage` is disabled.
 
File
- tests/
src/ FunctionalJavascript/ MediaImageTest.php, line 623  
Class
- MediaImageTest
 - Test Media Image specific functionality.
 
Namespace
Drupal\Tests\entity_embed\FunctionalJavascriptCode
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="{"image_style":"","image_link":""}" 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"]');
}