You are here

class DropzoneContext in Lightning Media 8.2

Same name and namespace in other branches
  1. 8 tests/contexts/DropzoneContext.behat.inc \Acquia\LightningExtension\Context\DropzoneContext
  2. 8.3 tests/contexts/DropzoneContext.behat.inc \Acquia\LightningExtension\Context\DropzoneContext

Contains step definitions for interacting with DropzoneJS widgets.

@internal This class is part of Lightning's internal testing code. It is not an API and should not be extended. This class will be marked final, and all protected members will be made private, in Lightning Media 3.x.

Hierarchy

  • class \Acquia\LightningExtension\Context\DropzoneContext extends \Drupal\DrupalExtension\Context\DrupalSubContextBase

Expanded class hierarchy of DropzoneContext

File

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

Namespace

Acquia\LightningExtension\Context
View source
class DropzoneContext extends DrupalSubContextBase {

  /**
   * Attaches a file to a dropzone.
   *
   * @param string $file
   *   The file to attach, relative to the file directory configured for Mink.
   *
   * @When I attach the file :file to the dropzone
   */
  public function attachFileToDropzone($file) {
    $this
      ->getSession()
      ->executeScript('Dropzone.instances[0].hiddenFileInput.name = "file"');
    $this
      ->getContext(MinkContext::class)
      ->attachFileToField('file', $file);

    // @todo: React when the upload actually completes.
    sleep(3);
  }

  /**
   * Uploads multiple files into the media library using Dropzone.
   *
   * @param \Behat\Gherkin\Node\PyStringNode $files
   *
   * @When I upload the following files:
   */
  public function uploadMultiple(PyStringNode $files) {
    $assert = $this
      ->assertSession();
    $this
      ->visitPath('/admin/content/media');
    $assert
      ->elementExists('named', [
      'link',
      'Bulk upload',
    ])
      ->click();

    // Wait for the dropzone to be initialized.
    sleep(3);
    $files = $files
      ->getStrings();
    foreach ($files as $file) {
      $this
        ->attachFileToDropzone($file);
    }
    $assert
      ->elementExists('named', [
      'button',
      'Continue',
    ])
      ->press();
    for ($i = 0; $i < count($files); $i++) {
      $assert
        ->elementExists('named', [
        'button',
        'Save',
      ])
        ->press();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DropzoneContext::attachFileToDropzone public function Attaches a file to a dropzone.
DropzoneContext::uploadMultiple public function Uploads multiple files into the media library using Dropzone.