public function BulkUploadTest::testBulkUpload in Lightning Media 8.4
Same name and namespace in other branches
- 8.3 modules/lightning_media_bulk_upload/tests/src/FunctionalJavascript/BulkUploadTest.php \Drupal\Tests\lightning_media_bulk_upload\FunctionalJavascript\BulkUploadTest::testBulkUpload()
Tests bulk uploading files into the media library with a dropzone.
File
- modules/
lightning_media_bulk_upload/ tests/ src/ FunctionalJavascript/ BulkUploadTest.php, line 43
Class
- BulkUploadTest
- Tests bulk upload of files into the media library.
Namespace
Drupal\Tests\lightning_media_bulk_upload\FunctionalJavascriptCode
public function testBulkUpload() {
$page = $this
->getSession()
->getPage();
$account = $this
->drupalCreateUser([
'access media overview',
'create media',
'update media',
'dropzone upload files',
'view the administration theme',
]);
$this
->drupalLogin($account);
// Confirm that Bulk upload link is present on the grid display of the
// administrative media overview.
$this
->drupalGet('/admin/content/media-grid');
$this
->assertSession()
->linkExists('Bulk upload');
// Confirm that Bulk upload link is present on the table display of the
// administrative media overview.
$this
->drupalGet('/admin/content/media');
$page
->clickLink('Bulk upload');
// Wait for the dropzone to be initialized.
sleep(3);
$files = [
'test.jpg',
'test.mp3',
'test.mp4',
'test.pdf',
];
foreach ($files as $file) {
$file = __DIR__ . "/../../../../../tests/files/{$file}";
$this
->assertFileExists($file);
$this
->getSession()
->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');
}
// Ensure all the files were actually saved, and have the current user as
// their owner.
$saved_files = $this->container
->get('entity_type.manager')
->getStorage('file')
->loadByProperties([
'filename' => $files,
'uid' => $account
->id(),
]);
$this
->assertSame(count($saved_files), count($files));
$this
->drupalGet('/admin/content/media');
// @todo Make this linkExists. For whatever reason, that assertion fails and
// I don't really feel like debugging it.
array_walk($files, [
$this
->assertSession(),
'pageTextContains',
]);
}