You are here

public function UploadWidgetTest::testUploadWidget in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/UploadWidgetTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\UploadWidgetTest::testUploadWidget()

Tests Entity Browser upload widget.

File

tests/src/FunctionalJavascript/UploadWidgetTest.php, line 30

Class

UploadWidgetTest
Tests the Upload Widget.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testUploadWidget() {

  /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
  $browser = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_browser')
    ->load('test_entity_browser_standalone_upload');
  $page = $this
    ->getSession()
    ->getPage();

  // Make sure the test file is not present beforehand.
  $this
    ->assertFileNotExists('public://druplicon.png');

  // Go to the widget standalone page and test the upload.
  $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');

  // Check if the file was correctly uploaded to the EB destination.
  $this
    ->assertFileExists('public://druplicon.png');

  // Now change upload location and submit label and check again.
  $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');

  // Check if the file was correctly uploaded to the EB destination.
  $this
    ->assertFileExists('public://some_location/druplicon.png');
}