You are here

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

Tests tabs widget selector.

File

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

Class

EntityBrowserTest
Tests the entity_browser.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testTabsWidgetSelector() {

  // Sets the tabs widget selector.

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

  // Create a file.
  $image = $this
    ->createFile('llama');

  // Create a second file.
  $image2 = $this
    ->createFile('llama2');
  $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
    ->assertSession()
    ->linkExists('dummy');
  $this
    ->assertSession()
    ->linkExists('view');
  $this
    ->assertSession()
    ->linkExists('upload');
  $this
    ->assertEquals('is-active active', $this
    ->getSession()
    ->getPage()
    ->findLink('view')
    ->getAttribute('class'));
  $this
    ->getSession()
    ->getPage()
    ->checkField('entity_browser_select[file:' . $image
    ->id() . ']');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Select entities');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->waitForAjaxToFinish();
  $this
    ->assertSession()
    ->pageTextContains('llama.jpg');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_test_entity_browser_file');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('upload');

  // This is producing an error. Still investigating
  // InvalidStateError: DOM Exception 11: An attempt was made to use an object
  // that is not, or is no longer, usable.
  // $uri = $this->container
  // ->get('file_system')
  // ->realpath($image2->getFileUri());
  // $edit = [
  // 'files[upload][]' => $uri,
  // ];
  // $this->drupalPostForm(NULL, $edit, 'Select files');.
  \Drupal::state()
    ->set('eb_test_dummy_widget_access', FALSE);
  $this
    ->drupalGet('entity-browser/iframe/test_entity_browser_file');
  $this
    ->assertSession()
    ->linkNotExists('dummy');
  $this
    ->assertSession()
    ->linkExists('view');
  $this
    ->assertSession()
    ->linkExists('upload');

  // Commenting out header checks for now:
  // Behat\Mink\Exception\UnsupportedDriverActionException: Response headers are not available
  // from Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver
  // $this->assertHeader('X-Drupal-Cache-Contexts', 'eb_dummy');
  // Move dummy widget to the first place and make sure it does not appear.
  $browser = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_browser')
    ->load('test_entity_browser_file');
  $browser
    ->getWidget('cbc59500-04ab-4395-b063-c561f0e3bf80')
    ->setWeight(-15);
  $browser
    ->save();
  $this
    ->drupalGet('entity-browser/iframe/test_entity_browser_file');
  $this
    ->assertSession()
    ->linkNotExists('dummy');
  $this
    ->assertSession()
    ->linkExists('view');
  $this
    ->assertSession()
    ->linkExists('upload');
  $this
    ->assertSession()
    ->pageTextNotContains('This is dummy widget.');
}