You are here

public function ImageBrowserCardinalityTest::testCardinality in Lightning Media 8.4

Same name and namespace in other branches
  1. 8.3 modules/lightning_media_image/tests/src/FunctionalJavascript/ImageBrowserCardinalityTest.php \Drupal\Tests\lightning_media_image\FunctionalJavascript\ImageBrowserCardinalityTest::testCardinality()

Tests that cardinality is enforced in the image browser.

File

modules/lightning_media_image/tests/src/FunctionalJavascript/ImageBrowserCardinalityTest.php, line 139

Class

ImageBrowserCardinalityTest
Tests that the image browser handles field cardinality correctly.

Namespace

Drupal\Tests\lightning_media_image\FunctionalJavascript

Code

public function testCardinality() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet('/node/add/page');
  $this
    ->openImageBrowser('Multi-Image');
  $items = $this
    ->waitForItems();
  $this
    ->assertGreaterThanOrEqual(4, count($items));
  $this
    ->selectItem($items[0]);
  $this
    ->selectItem($items[1]);
  $page
    ->pressButton('Select');
  $this
    ->waitForEntityBrowserToClose();

  // Wait for the selected items to actually appear on the page.
  $assert_session
    ->waitForElement('css', '[data-drupal-selector="edit-field-multi-image-current"] [data-entity-id]');
  $this
    ->openImageBrowser('Multi-Image');
  $items = $this
    ->waitForItems();
  $this
    ->assertGreaterThanOrEqual(4, count($items));
  $this
    ->selectItem($items[2]);
  $disabled = $page
    ->waitFor(10, function (DocumentElement $page) {
    return $page
      ->findAll('css', '[data-selectable].disabled');
  });
  $this
    ->assertGreaterThanOrEqual(3, count($disabled));

  // Close the image browser without selecting anything.
  $this
    ->getSession()
    ->switchToIFrame(NULL);
  $assert_session
    ->elementExists('css', '.ui-dialog')
    ->pressButton('Close');
  $this
    ->openImageBrowser('Unlimited Images');
  $items = $this
    ->waitForItems();
  $this
    ->assertGreaterThanOrEqual(4, count($items));
  $this
    ->selectItem($items[0]);
  $this
    ->selectItem($items[1]);
  $this
    ->selectItem($items[2]);
  $page
    ->pressButton('Select');
  $this
    ->waitForEntityBrowserToClose();

  // Wait for the selected items to actually appear on the page.
  $assert_session
    ->waitForElement('css', '[data-drupal-selector="edit-field-unlimited-images-current"] [data-entity-id]');
  $this
    ->openImageBrowser('Unlimited Images');
  $items = $this
    ->waitForItems();
  $this
    ->assertGreaterThanOrEqual(4, count($items));
  $this
    ->selectItem($items[3]);
  $assert_session
    ->elementsCount('css', '[data-selectable].disabled', 0);
}