DropzoneJsElementTest.php in DropzoneJS 8
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
->installSchema('system', 'router');
$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
->assertFalse($this
->xpath("{$xpath_base}/label[text()='Not DropzoneJs element']"));
$this
->assertTrue($this
->xpath("{$xpath_base}/label[text()='DropzoneJs element']"));
$this
->assertTrue($this
->xpath("{$xpath_base}/div[contains(@class, 'dropzone-enable')]"));
$this
->assertTrue($this
->xpath("{$xpath_base}/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]"));
$this
->assertTrue($this
->xpath("{$xpath_base}/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]"));
$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')]"));
}
}