Skip to content

Commit a6a6233

Browse files
committed
Removing hook_file_validate test module.
1 parent b9ade93 commit a6a6233

File tree

7 files changed

+28
-55
lines changed

7 files changed

+28
-55
lines changed

.github/workflows/testing.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
# # php-versions: ['8.1', '8.2']
17-
# # drupal-core: ['10.3.x']
18-
# phpstan: ['0']
16+
php-versions: ['8.1', '8.2']
17+
drupal-core: ['10.3.x']
18+
phpstan: ['0']
1919
include:
2020
# Extra run to test older supported Drupal 10.2.x.
21-
# - php-versions: '8.1'
22-
# drupal-core: '10.2.x'
23-
# phpstan: '0'
21+
- php-versions: '8.1'
22+
drupal-core: '10.2.x'
23+
phpstan: '0'
2424
# We only need to run PHPStan once on the latest PHP version.
25-
# - php-versions: '8.3'
26-
# drupal-core: '10.3.x'
27-
# phpstan: '1'
25+
- php-versions: '8.3'
26+
drupal-core: '10.3.x'
27+
phpstan: '1'
2828
- php-versions: '8.3'
2929
drupal-core: '11.0.x'
3030
phpstan: '1'

src/EventSubscriber/SubrequestSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function onKernelRequestFinished(FinishRequestEvent $event): void {
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
public static function getSubscribedEvents() {
70+
public static function getSubscribedEvents(): array {
7171
return [
7272
KernelEvents::REQUEST => 'onKernelRequest',
7373
KernelEvents::FINISH_REQUEST => 'onKernelRequestFinished',

src/GraphQL/Utility/FileUpload.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class FileUpload {
3737
use StringTranslationTrait;
3838

3939
/**
40-
* The file storage where we will create new file entities from.
40+
* The entity storage for the 'file' entity type.
4141
*
42-
* @var \Drupal\Core\Entity\EntityStorageInterface
42+
* @var \Drupal\file\FileStorageInterface
4343
*/
4444
protected $fileStorage;
4545

@@ -137,7 +137,9 @@ public function __construct(
137137
ImageFactory $image_factory,
138138
FileValidatorInterface $file_validator,
139139
) {
140-
$this->fileStorage = $entityTypeManager->getStorage('file');
140+
/** @var \Drupal\file\FileStorageInterface $file_storage */
141+
$file_storage = $entityTypeManager->getStorage('file');
142+
$this->fileStorage = $file_storage;
141143
$this->currentUser = $currentUser;
142144
$this->mimeTypeGuesser = $mimeTypeGuesser;
143145
$this->fileSystem = $fileSystem;
@@ -268,7 +270,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
268270

269271
try {
270272
// Begin building file entity.
271-
/** @var \Drupal\Core\Entity\EntityInterface $file */
273+
/** @var \Drupal\file\FileInterface $file */
272274
$file = $this->fileStorage->create([]);
273275
$file->setOwnerId($this->currentUser->id());
274276
$file->setFilename($prepared_filename);
@@ -281,10 +283,11 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
281283
// Validate against fileValidator first with the temporary path.
282284
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */
283285
$errors = $this->fileValidator->validate($file, $validators);
284-
if (!empty($errors)) {
286+
if (count($errors) > 0) {
285287
$response->addViolations($errors);
286288
return $response;
287289
}
290+
288291
// Validate Image resolution.
289292
$maxResolution = $settings['max_resolution'] ?? 0;
290293
$minResolution = $settings['min_resolution'] ?? 0;
@@ -323,7 +326,6 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
323326
}
324327

325328
$file->save();
326-
327329
$response->setFileEntity($file);
328330
return $response;
329331
}
@@ -515,7 +517,7 @@ protected function prepareFilename(string $filename, array &$validators): string
515517

516518
$passes_validation = FALSE;
517519
if (!empty($validators['FileExtension']['extensions'])) {
518-
/** @var \Drupal\Core\Entity\EntityInterface $file */
520+
/** @var \Drupal\file\FileInterface $file */
519521
$file = $this->fileStorage->create([]);
520522
$file->setFilename($filename);
521523
$passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions']));

tests/modules/graphql_file_validate/graphql_file_validate.info.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/modules/graphql_file_validate/graphql_file_validate.module

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/src/Kernel/AlterableSchemaTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,18 @@ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded(): void
114114
$this->assertSame([
115115
'errors' => [
116116
0 => [
117-
'message' => 'Internal server error',
117+
'message' => 'Cannot query field "empty" on type "Result".',
118118
'extensions' => [
119-
'category' => 'internal',
119+
'category' => 'graphql',
120120
],
121121
'locations' => [
122122
0 => [
123123
'line' => 1,
124124
'column' => 37,
125125
],
126126
],
127-
'path' => [
128-
'alterableQuery',
129-
// Reference to our variable in the error.
130-
'empty',
131-
],
132127
],
133128
],
134-
'data' => [
135-
'alterableQuery' => NULL,
136-
],
137129
], json_decode($result->getContent(), TRUE));
138130
}
139131

tests/src/Kernel/Framework/UploadFileServiceTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
*/
1616
class UploadFileServiceTest extends GraphQLTestBase {
1717

18-
/**
19-
* {@inheritdoc}
20-
*/
21-
protected static $modules = ['file', 'graphql_file_validate'];
22-
2318
/**
2419
* The FileUpload object we want to test, gets prepared in setUp().
2520
*
2621
* @var \Drupal\graphql\GraphQL\Utility\FileUpload
2722
*/
2823
protected $uploadService;
2924

25+
/**
26+
* Modules to enable.
27+
*
28+
* @var array
29+
*/
30+
protected static $modules = ['file'];
31+
3032
/**
3133
* Gets the file path of the source file.
3234
*
@@ -67,7 +69,6 @@ public function testSuccess(): void {
6769
'file_directory' => 'test',
6870
]);
6971
$file_entity = $file_upload_response->getFileEntity();
70-
7172
$this->assertSame('public://test/test.txt', $file_entity->getFileUri());
7273
$this->assertFileExists($file_entity->getFileUri());
7374
}

0 commit comments

Comments
 (0)