You are here

public function ImageBrowserTest::testUpload in Lightning Media 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/FunctionalJavascript/ImageBrowserTest.php \Drupal\Tests\lightning_media\FunctionalJavascript\ImageBrowserTest::testUpload()

Tests uploading an image in the image browser.

File

tests/src/FunctionalJavascript/ImageBrowserTest.php, line 75

Class

ImageBrowserTest
Tests the image browser shipped with Lightning Media Image.

Namespace

Drupal\Tests\lightning_media\FunctionalJavascript

Code

public function testUpload() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $account = $this
    ->drupalCreateUser([
    'create page content',
  ]);
  $account
    ->addRole('media_creator');
  $account
    ->save();
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/node/add/page');
  $assert_session
    ->elementExists('css', '.field--name-field-hero-image')
    ->pressButton('Select Image(s)');
  $this
    ->waitForEntityBrowser('image_browser');
  $assert_session
    ->waitForLink('Upload')
    ->click();

  // This helps stabilize the next couple of calls; without it, the
  // upload is more likely to randomly fail. It's not clear why this
  // is the case, but repeated testing on Travis CI seems to support
  // it.
  $assert_session
    ->assertWaitOnAjaxRequest();
  $path = realpath(__DIR__ . '/../../files/test.jpg');
  $this
    ->assertNotEmpty($path);
  $assert_session
    ->waitForField('File')
    ->attachFile($path);
  $assert_session
    ->waitForField('Name')
    ->setValue('Behold, a generic logo');
  $summary = $assert_session
    ->elementExists('css', 'details > summary:contains(Crop image)');
  $this
    ->assertTrue($summary
    ->getParent()
    ->hasAttribute('open'));
  $assert_session
    ->elementExists('css', 'details > summary:contains(Freeform)');
  $page
    ->pressButton('Select');
  $this
    ->waitForEntityBrowserToClose();
  $assert_session
    ->elementNotExists('css', "table[drupal-data-selector='edit-image-current'] td.empty");
}