You are here

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

Tests dropdown widget selector.

File

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

Class

EntityBrowserTest
Tests the entity_browser.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testDropdownWidgetSelector() {

  // Sets the dropdown widget selector.

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

  // 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
    ->assertSession()
    ->selectExists('widget');

  // Dummy.
  $this
    ->assertSession()
    ->optionExists('widget', 'cbc59500-04ab-4395-b063-c561f0e3bf80');

  // Upload.
  $this
    ->assertSession()
    ->optionExists('widget', '2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');

  // View.
  $this
    ->assertSession()
    ->optionExists('widget', '774798f1-5ec5-4b63-84bd-124cd51ec07d');

  // Selects the view widget.
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('widget', '774798f1-5ec5-4b63-84bd-124cd51ec07d');
  $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');

  // Causes a fatal.
  // Selects the upload widget.
  // $this->getSession()
  // ->getPage()
  // ->selectFieldOption('widget', '2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');.
  \Drupal::state()
    ->set('eb_test_dummy_widget_access', FALSE);
  $this
    ->drupalGet('entity-browser/iframe/test_entity_browser_file');

  // Dummy.
  $this
    ->assertSession()
    ->optionNotExists('widget', 'cbc59500-04ab-4395-b063-c561f0e3bf80');

  // Upload.
  $this
    ->assertSession()
    ->optionExists('widget', '2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');

  // View.
  $this
    ->assertSession()
    ->optionExists('widget', '774798f1-5ec5-4b63-84bd-124cd51ec07d');

  // 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');

  // Dummy.
  $this
    ->assertSession()
    ->optionNotExists('widget', 'cbc59500-04ab-4395-b063-c561f0e3bf80');

  // Upload.
  $this
    ->assertSession()
    ->optionExists('widget', '2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');

  // View.
  $this
    ->assertSession()
    ->optionExists('widget', '774798f1-5ec5-4b63-84bd-124cd51ec07d');
  $this
    ->assertSession()
    ->pageTextNotContains('This is dummy widget.');
}