Skip to content

Commit

Permalink
Removing hook_file_validate test module.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jul 25, 2024
1 parent b9ade93 commit e687fc7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 34 deletions.
15 changes: 9 additions & 6 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class FileUpload {
use StringTranslationTrait;

/**
* The file storage where we will create new file entities from.
* The entity storage for the 'file' entity type.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
* @var \Drupal\file\FileStorageInterface
*/
protected $fileStorage;

Expand Down Expand Up @@ -137,7 +137,9 @@ public function __construct(
ImageFactory $image_factory,
FileValidatorInterface $file_validator,
) {
$this->fileStorage = $entityTypeManager->getStorage('file');
/** @var \Drupal\file\FileStorageInterface $file_storage */
$file_storage = $entityTypeManager->getStorage('file');
$this->fileStorage = $file_storage;
$this->currentUser = $currentUser;
$this->mimeTypeGuesser = $mimeTypeGuesser;
$this->fileSystem = $fileSystem;
Expand Down Expand Up @@ -268,7 +270,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi

try {
// Begin building file entity.
/** @var \Drupal\Core\Entity\EntityInterface $file */
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage->create([]);
$file->setOwnerId($this->currentUser->id());
$file->setFilename($prepared_filename);
Expand Down Expand Up @@ -323,8 +325,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
}

$file->save();

dump($file);
$response->setFileEntity($file);
dump($response->getFileEntity());
return $response;
}
finally {
Expand Down Expand Up @@ -515,7 +518,7 @@ protected function prepareFilename(string $filename, array &$validators): string

$passes_validation = FALSE;
if (!empty($validators['FileExtension']['extensions'])) {
/** @var \Drupal\Core\Entity\EntityInterface $file */
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage->create([]);
$file->setFilename($filename);
$passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions']));
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions tests/modules/graphql_file_validate/graphql_file_validate.module

This file was deleted.

14 changes: 8 additions & 6 deletions tests/src/Kernel/Framework/UploadFileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
*/
class UploadFileServiceTest extends GraphQLTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = ['file', 'graphql_file_validate'];

/**
* The FileUpload object we want to test, gets prepared in setUp().
*
* @var \Drupal\graphql\GraphQL\Utility\FileUpload
*/
protected $uploadService;

/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['file'];

/**
* Gets the file path of the source file.
*
Expand Down Expand Up @@ -67,7 +69,7 @@ public function testSuccess(): void {
'file_directory' => 'test',
]);
$file_entity = $file_upload_response->getFileEntity();

dump($file_entity);
$this->assertSame('public://test/test.txt', $file_entity->getFileUri());
$this->assertFileExists($file_entity->getFileUri());
}
Expand Down

0 comments on commit e687fc7

Please sign in to comment.