DropzoneJsElementTest.php in DropzoneJS 8.2
File
tests/src/Kernel/DropzoneJsElementTest.php
View source
<?php
namespace Drupal\Tests\dropzonejs\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
class DropzoneJsElementTest extends KernelTestBase {
public static $modules = [
'system',
'file',
'user',
'dropzonejs',
'dropzonejs_test',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$role = Role::create([
'id' => RoleInterface::ANONYMOUS_ID,
]);
$role
->grantPermission('dropzone upload files');
$role
->save();
}
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')]";
$this
->assertEmpty($this
->xpath("{$xpath_base}/label[text()='Not DropzoneJS element']"));
$this
->assertNotEmpty($this
->xpath("{$xpath_base}/label[text()='DropzoneJS element']"));
$this
->assertNotEmpty($this
->xpath("{$xpath_base}/div[contains(@class, 'dropzone-enable')]"));
$this
->assertNotEmpty($this
->xpath("{$xpath_base}/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]"));
$this
->assertNotEmpty($this
->xpath("{$xpath_base}/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]"));
$this
->assertNotEmpty($this
->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]"));
$this
->assertNotEmpty($this
->xpath("/html/body/script[contains(@src, 'dropzonejs/js/dropzone.integration.js')]"));
}
}