You are here

public function MediaLibraryIntegrationTest::testFocalPointMediaField in Focal Point 8

Tests Focal Point integration with the media library.

File

tests/src/FunctionalJavascript/MediaLibraryIntegrationTest.php, line 103

Class

MediaLibraryIntegrationTest
Tests Focal Point's integration with Media Library.

Namespace

Drupal\Tests\focal_point\FunctionalJavascript

Code

public function testFocalPointMediaField() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $files = $this
    ->getTestFiles('image');
  $path = $this->container
    ->get('file_system')
    ->realpath($files[0]->uri);
  $this
    ->assertNotEmpty($path);

  // Upload an image and ensure that a single Focal Point widget shows up.
  $this
    ->drupalGet('/node/add/article');
  $page
    ->pressButton('Add media');
  $file_field = $assert_session
    ->waitForField('Add file');
  $this
    ->assertNotEmpty($file_field);
  $file_field
    ->attachFile($path);
  $widget_exists = $this
    ->getSession()
    ->getPage()
    ->waitFor(10, function (DocumentElement $page) {
    $elements = $page
      ->findAll('css', '[data-media-library-added-delta] .focal-point-indicator');
    return count($elements) === 1;
  });
  $this
    ->assertTrue($widget_exists);
}