You are here

public function DropzoneContext::uploadMultiple in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.2 tests/contexts/DropzoneContext.behat.inc \Acquia\LightningExtension\Context\DropzoneContext::uploadMultiple()

Uploads multiple files into the media library using Dropzone.

@When I upload the following files:

Parameters

\Behat\Gherkin\Node\PyStringNode $files: A list of local file paths to upload.

File

tests/contexts/DropzoneContext.behat.inc, line 36

Class

DropzoneContext
Contains step definitions for interacting with DropzoneJS widgets.

Namespace

Acquia\LightningExtension\Context

Code

public function uploadMultiple(PyStringNode $files) {
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->visitPath('/admin/content/media');
  $page
    ->clickLink('Bulk upload');

  // Wait for the dropzone to be initialized.
  sleep(3);
  $files = $files
    ->getStrings();
  foreach ($files as $file) {
    $file = __DIR__ . '/../files/' . $file;
    Assert::fileExists($file);
    $session = $this
      ->getSession();
    $session
      ->executeScript('Dropzone.instances[0].hiddenFileInput.name = "file"');
    $page
      ->attachFileToField('file', $file);

    // @todo React when the upload actually completes.
    sleep(3);
  }
  $page
    ->pressButton('Continue');
  for ($i = 0; $i < count($files); $i++) {
    $page
      ->pressButton('Save');
  }
}