You are here

public function EntityBrowserTest::testSingleWidgetSelector 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::testSingleWidgetSelector()

Tests single widget selector.

File

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

Class

EntityBrowserTest
Tests the entity_browser.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testSingleWidgetSelector() {

  // Sets the single widget selector.

  /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
  $browser = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_browser')
    ->load('test_entity_browser_file');
  $this
    ->assertEquals($browser
    ->getWidgetSelector()
    ->getPluginId(), 'single', 'Widget selector is set to single.');

  // Create a file.
  $image = $this
    ->createFile('llama');
  $this
    ->drupalGet('node/add/article');
  $this
    ->assertSession()
    ->linkExists('Select entities');
  $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();

  // Test the Edit functionality.
  $this
    ->assertSession()
    ->pageTextContains('llama.jpg');
  $this
    ->assertSession()
    ->buttonExists('Edit');

  // @TODO Test the edit button.
  // Test the Delete functionality.
  $this
    ->assertSession()
    ->buttonExists('Remove');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Remove');
  $this
    ->waitForAjaxToFinish();
  $this
    ->assertSession()
    ->pageTextNotContains('llama.jpg');
  $this
    ->assertSession()
    ->linkExists('Select entities');
}