You are here

public function CKEditorMediaBrowserTest::testImageEmbed in Lightning Media 8.3

Tests that the image embed plugin is used to embed an image.

File

tests/src/FunctionalJavascript/CKEditorMediaBrowserTest.php, line 194

Class

CKEditorMediaBrowserTest
Tests the media browser's integration with CKEditor.

Namespace

Drupal\Tests\lightning_media\FunctionalJavascript

Code

public function testImageEmbed() {
  $session = $this
    ->getSession();
  $uri = uniqid('public://') . '.png';
  $uri = $this
    ->getRandomGenerator()
    ->image($uri, '640x480', '800x600');
  $this
    ->assertFileExists($uri);
  $image = File::create([
    'uri' => $uri,
  ]);
  $image
    ->save();
  $media = $this
    ->addMedia([
    'bundle' => 'image',
    'name' => 'Foobar',
    'image' => $image
      ->id(),
  ]);
  $media->image->alt = 'I am the greetest';
  $media
    ->save();
  $this
    ->drupalGet('/node/add/page');
  $this
    ->open();
  $items = $this
    ->waitForItems();
  $this
    ->selectItem($items[0]);
  $session
    ->getPage()
    ->pressButton('Place');
  $session
    ->switchToIFrame(NULL);
  $embed_form = $this
    ->waitForImageEmbedForm();
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->optionExists('Image style', 'Cropped: Freeform', $embed_form);
  $assert_session
    ->fieldValueEquals('Alternate text', 'I am the greetest', $embed_form);
  $assert_session
    ->fieldValueEquals('attributes[title]', 'Foobar', $embed_form);
}