You are here

public function FileBrowserTest::testFileBrowserView in File Entity Browser 8

Tests that selecting files in the view works.

File

tests/src/FunctionalJavascript/FileBrowserTest.php, line 34

Class

FileBrowserTest
Tests the file_browser module.

Namespace

Drupal\Tests\file_browser\FunctionalJavascript

Code

public function testFileBrowserView() {

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
  $form_display = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_form_display')
    ->load('node.article.default');
  $form_display
    ->setComponent('field_reference', [
    'type' => 'entity_browser_entity_reference',
    'settings' => [
      'entity_browser' => 'browse_files',
      'field_widget_display' => 'label',
      'open' => TRUE,
    ],
  ])
    ->save();

  // Create a file.
  $image = $this
    ->createFile('llama', 'jpg');
  $this
    ->drupalGet('node/add/article');

  // Open the browser and select a file.
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_browse_files');
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Files listing');
  $this
    ->clickViewEntity('file:' . $image
    ->id());
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Use selected');

  // Switch back to the main page and assert that the file was selected.
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('llama.jpg');
}