You are here

public function EmbeddedMediaTest::testEmbedImageMedia in Lightning Media 8.3

Tests embedding image media with custom alt and title text.

File

tests/src/FunctionalJavascript/EmbeddedMediaTest.php, line 98

Class

EmbeddedMediaTest
Tests embedding media items in CKEditor using the media browser.

Namespace

Drupal\Tests\lightning_media\FunctionalJavascript

Code

public function testEmbedImageMedia() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $random = $this
    ->getRandomGenerator();
  $uri = $random
    ->image(uniqid('public://random_') . '.png', '240x240', '640x480');
  $file = File::create([
    'uri' => $uri,
  ]);
  $file
    ->setMimeType('image/png');
  $file
    ->setTemporary();
  $file
    ->save();

  /** @var \Drupal\media\MediaInterface $media */
  $media = Media::create([
    'bundle' => 'image',
    'name' => $random
      ->name(32),
    'image' => $file
      ->id(),
    'field_media_in_library' => TRUE,
  ]);
  $media
    ->setPublished()
    ->save();
  $this
    ->drupalGet('/node/add/page');
  $page
    ->fillField('Title', 'Foobar');
  $this
    ->open();
  $items = $this
    ->waitForItems();
  $this
    ->selectItem($items[0]);
  $page
    ->pressButton('Place');
  $embed_form = $this
    ->waitForImageEmbedForm();
  $embed_form
    ->selectFieldOption('Image style', 'medium');
  $embed_form
    ->fillField('Alternate text', 'Behold my image of randomness');
  $embed_form
    ->fillField('Title', 'Ye gods!');
  $this
    ->submitEmbedForm();
  $page
    ->pressButton('Save');
  $assert_session
    ->responseContains('Behold my image of randomness');
  $assert_session
    ->responseContains('Ye gods!');
}