You are here

public function DropzoneJsElementTest::testDropzoneJsElement in DropzoneJS 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/DropzoneJsElementTest.php \Drupal\Tests\dropzonejs\Kernel\DropzoneJsElementTest::testDropzoneJsElement()

Tests that the dropzonejs element appears.

File

tests/src/Kernel/DropzoneJsElementTest.php, line 46

Class

DropzoneJsElementTest
Tests related to the dropzoneJs element.

Namespace

Drupal\Tests\dropzonejs\Kernel

Code

public function testDropzoneJsElement() {
  $this->container
    ->get('router.builder')
    ->rebuild();
  $form = \Drupal::formBuilder()
    ->getForm('\\Drupal\\dropzonejs_test\\Form\\DropzoneJsTestForm');
  $this
    ->render($form);
  $xpath_base = "//div[contains(@class, 'form-item-dropzonejs')]";

  // Label.
  $this
    ->assertFalse($this
    ->xpath("{$xpath_base}/label[text()='Not DropzoneJs element']"));
  $this
    ->assertTrue($this
    ->xpath("{$xpath_base}/label[text()='DropzoneJs element']"));

  // Element where dropzonejs is attached to.
  $this
    ->assertTrue($this
    ->xpath("{$xpath_base}/div[contains(@class, 'dropzone-enable')]"));

  // Uploaded files input.
  $this
    ->assertTrue($this
    ->xpath("{$xpath_base}/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]"));

  // Upload files path.
  $this
    ->assertTrue($this
    ->xpath("{$xpath_base}/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]"));

  // Js is attached.
  $this
    ->assertTrue($this
    ->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]"));
  $this
    ->assertTrue($this
    ->xpath("/html/body/script[contains(@src, 'dropzonejs/js/dropzone.integration.js')]"));
}