Commit 365cc0e6 authored by katherined's avatar katherined Committed by chr.fritsch

Issue #3095062 by katherined, alexpott, Berdir, chr.fritsch: Drupal 9...

Issue #3095062 by katherined, alexpott, Berdir, chr.fritsch: Drupal 9 deprecated code report for DropzoneJS
parent 0f54da5a
name: dropzonejs
type: module
description: DropzoneJS
core: 8.x
core_version_requirement: ^8.8 || ^9
package: Media
dependencies:
- drupal:file
services:
dropzonejs.upload_save:
class: Drupal\dropzonejs\DropzoneJsUploadSave
arguments: ['@entity_type.manager', '@file.mime_type.guesser', '@file_system', '@logger.factory', '@renderer', '@config.factory', '@token', '@messenger']
arguments: ['@entity_type.manager', '@file.mime_type.guesser', '@file_system', '@logger.factory', '@renderer', '@config.factory', '@token', '@messenger', '@stream_wrapper_manager']
dropzonejs.upload_handler:
class: Drupal\dropzonejs\UploadHandler
arguments: ['@request_stack', '@config.factory', '@transliteration', '@language_manager']
name: DropzoneJS entity browser widget
type: module
description: DropzoneJS Entity browser widget
core: 8.x
core_version_requirement: ^8.8 || ^9
package: Media
dependencies:
- drupal:file
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Utility\Token;
use Drupal\file\FileInterface;
......@@ -81,6 +82,13 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
*/
protected $messenger;
/**
* The stream wrapper manager.
*
* @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
*/
protected $streamWrapperManager;
/**
* Construct the DropzoneUploadSave object.
*
......@@ -100,8 +108,10 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
* The token service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
* The stream wrapper manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, MimeTypeGuesserInterface $mimetype_guesser, FileSystemInterface $file_system, LoggerChannelFactoryInterface $logger_factory, RendererInterface $renderer, ConfigFactoryInterface $config_factory, Token $token, MessengerInterface $messenger) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, MimeTypeGuesserInterface $mimetype_guesser, FileSystemInterface $file_system, LoggerChannelFactoryInterface $logger_factory, RendererInterface $renderer, ConfigFactoryInterface $config_factory, Token $token, MessengerInterface $messenger, StreamWrapperManagerInterface $stream_wrapper_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->mimeTypeGuesser = $mimetype_guesser;
$this->fileSystem = $file_system;
......@@ -110,6 +120,7 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
$this->configFactory = $config_factory;
$this->token = $token;
$this->messenger = $messenger;
$this->streamWrapperManager = $stream_wrapper_manager;
}
/**
......@@ -117,7 +128,7 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
*/
public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, array $validators = []) {
// Create the file entity.
$uri = file_stream_wrapper_uri_normalize($uri);
$uri = $this->streamWrapperManager->normalizeUri($uri);
$file_info = new \SplFileInfo($uri);
/** @var \Drupal\file\FileInterface $file */
......@@ -229,8 +240,8 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
*/
protected function prepareDestination(FileInterface $file, $destination) {
// Assert that the destination contains a valid stream.
$destination_scheme = $this->fileSystem->uriScheme($destination);
if (!$this->fileSystem->validScheme($destination_scheme)) {
$destination_scheme = $this->streamWrapperManager::getScheme($destination);
if (!$this->streamWrapperManager->isValidScheme($destination_scheme)) {
return FALSE;
}
......
......@@ -3,7 +3,6 @@ type: module
description: 'Support module for DropzoneJs tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:media
- dropzonejs:dropzonejs
......
......@@ -31,7 +31,6 @@ class DropzoneJsElementTest extends KernelTestBase {
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'router');
$this->installEntitySchema('user');
/** @var \Drupal\user\RoleInterface $role */
......@@ -50,17 +49,17 @@ class DropzoneJsElementTest extends KernelTestBase {
$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']"));
$this->assertEmpty($this->xpath("$xpath_base/label[text()='Not DropzoneJs element']"));
$this->assertNotEmpty($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')]"));
$this->assertNotEmpty($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')]"));
$this->assertNotEmpty($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=')]"));
$this->assertNotEmpty($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')]"));
$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')]"));
}
}
......@@ -57,15 +57,11 @@ class DropzoneJsUploadControllerTest extends KernelTestBase {
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'router');
$this->installConfig('dropzonejs');
$this->installEntitySchema('user');
$this->filesDir = $this->siteDirectory . '/files';
$config = $this->container->get('config.factory');
$config->getEditable('system.file')
->set('path.temporary', $this->filesDir)
->save();
$this->setSetting('file_temp_path', $this->filesDir);
$this->tmpFile = tempnam('', $this->testfilePrefix);
file_put_contents($this->tmpFile, $this->testfileData);
......@@ -93,12 +89,12 @@ class DropzoneJsUploadControllerTest extends KernelTestBase {
$upload_handler = $this->container->get('dropzonejs.upload_handler');
$controller = new UploadController($upload_handler, $request);
$controller_result = $controller->handleUploads();
$this->assertTrue($controller_result instanceof JsonResponse);
$this->assertInstanceOf(JsonResponse::class, $controller_result);
$result = json_decode($controller_result->getContent());
$result_file = $this->filesDir . '/' . $result->result;
$this->assertStringEndsWith('-kaplya_aa1.jpg.txt', $result_file);
$this->assertTrue(file_exists($result_file));
$this->assertFileExists($result_file);
$this->assertEquals(file_get_contents($result_file), $this->testfileData);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment