UploadWidgetTest.php in Entity Browser 8.2
File
tests/src/FunctionalJavascript/UploadWidgetTest.php
View source
<?php
namespace Drupal\Tests\entity_browser\FunctionalJavascript;
use Drupal\user\Entity\Role;
class UploadWidgetTest extends EntityBrowserWebDriverTestBase {
public function setUp() {
parent::setUp();
$role = Role::load('authenticated');
$this
->grantPermissions($role, [
'access test_entity_browser_standalone_upload entity browser pages',
]);
}
public function testUploadWidget() {
$browser = $this->container
->get('entity_type.manager')
->getStorage('entity_browser')
->load('test_entity_browser_standalone_upload');
$page = $this
->getSession()
->getPage();
$this
->assertFileNotExists('public://druplicon.png');
$this
->drupalGet($browser
->getDisplay()
->path());
$page
->attachFileToField('edit-upload-upload', \Drupal::root() . '/core/misc/druplicon.png');
$this
->waitForAjaxToFinish();
$this
->assertSession()
->fieldExists('druplicon.png');
$page
->pressButton('Select files');
$this
->assertFileExists('public://druplicon.png');
$widget = $browser
->getWidget('2dc1ab07-2f8f-42c9-aab7-7eef7f8b7d87');
$config = $widget
->getConfiguration();
$config['settings']['upload_location'] = 'public://some_location';
$config['settings']['submit_text'] = 'Fancy submit';
$widget
->setConfiguration($config);
$browser
->save();
$this
->drupalGet($browser
->getDisplay()
->path());
$page
->attachFileToField('edit-upload-upload', \Drupal::root() . '/core/misc/druplicon.png');
$this
->waitForAjaxToFinish();
$this
->assertSession()
->fieldExists('druplicon.png');
$page
->pressButton('Fancy submit');
$this
->assertFileExists('public://some_location/druplicon.png');
}
}