You are here

public function EntityBrowserTest::testSingleCardinalityField in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/EntityBrowserTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserTest::testSingleCardinalityField()

Tests the field widget with a single-cardinality field.

File

tests/src/FunctionalJavascript/EntityBrowserTest.php, line 56

Class

EntityBrowserTest
Tests the entity_browser.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testSingleCardinalityField() {
  $this->container
    ->get('entity_type.manager')
    ->getStorage('field_storage_config')
    ->load('node.field_reference')
    ->setCardinality(1)
    ->save();

  // Create a file.
  $image = $this
    ->createFile('llama');
  $this
    ->drupalGet('node/add/article');
  $this
    ->assertSession()
    ->linkExists('Select entities');
  $this
    ->assertSession()
    ->pageTextContains('You can select one file.');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
  $this
    ->getSession()
    ->getPage()
    ->checkField('entity_browser_select[file:' . $image
    ->id() . ']');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Select entities');

  // Switch back to the main page.
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->waitForAjaxToFinish();

  // A selection has been made, so the message is no longer necessary.
  $this
    ->assertSession()
    ->pageTextNotContains('You can select one file.');
}