FileBrowserTest.php in File Entity Browser 8
File
tests/src/FunctionalJavascript/FileBrowserTest.php
View source
<?php
namespace Drupal\Tests\file_browser\FunctionalJavascript;
use Drupal\Tests\entity_browser\FunctionalJavascript\EntityBrowserWebDriverTestBase;
class FileBrowserTest extends EntityBrowserWebDriverTestBase {
public static $modules = [
'file_browser',
];
protected static $userPermissions = [
'access browse_files entity browser pages',
'create article content',
'access content',
'dropzone upload files',
];
public function testFileBrowserView() {
$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();
$image = $this
->createFile('llama', 'jpg');
$this
->drupalGet('node/add/article');
$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');
$this
->getSession()
->switchToIFrame();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('llama.jpg');
}
protected function clickViewEntity($entityId) {
$xpathViewRow = '//*[./*[contains(@class, "views-field-entity-browser-select") and .//input[@name="entity_browser_select[' . $entityId . ']"]]]';
$this
->assertSession()
->elementExists('xpath', $xpathViewRow)
->click();
}
}