From 8fac31e2e25eccc72719cf53fd4d266ce0ab91a0 Mon Sep 17 00:00:00 2001 From: Ankit Pathak <106175376+apathak18@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:47:43 +0000 Subject: [PATCH 01/18] Drupal 11 readiness. --- examples/graphql_composable/graphql_composable.info.yml | 2 +- examples/graphql_example/graphql_examples.info.yml | 2 +- graphql.info.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/graphql_composable/graphql_composable.info.yml b/examples/graphql_composable/graphql_composable.info.yml index 92ebd73cd..a891052cb 100644 --- a/examples/graphql_composable/graphql_composable.info.yml +++ b/examples/graphql_composable/graphql_composable.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^10.1 +core_version_requirement: ^10.1 || ^11 diff --git a/examples/graphql_example/graphql_examples.info.yml b/examples/graphql_example/graphql_examples.info.yml index 57bb865b3..8587aa2e8 100644 --- a/examples/graphql_example/graphql_examples.info.yml +++ b/examples/graphql_example/graphql_examples.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^10.1 +core_version_requirement: ^10.1 || ^11 diff --git a/graphql.info.yml b/graphql.info.yml index c8cc6d095..90852febe 100644 --- a/graphql.info.yml +++ b/graphql.info.yml @@ -3,6 +3,6 @@ type: module description: 'Base module for integrating GraphQL with Drupal.' package: GraphQL configure: graphql.config_page -core_version_requirement: ^10.1 +core_version_requirement: ^10.1 || ^11 dependencies: - typed_data:typed_data From 2eaece787ea9fddd0ab16c99a6cbd63c3a2833cf Mon Sep 17 00:00:00 2001 From: Ankit Pathak <106175376+apathak18@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:27:58 +0530 Subject: [PATCH 02/18] Update github workflow to ready for drupal next minor and major version. --- .github/workflows/testing.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ff8c178a9..b9af5b829 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -29,6 +29,9 @@ jobs: - php-versions: '8.3' drupal-core: '10.3.x' phpstan: '1' + - php-versions: '8.3' + drupal-core: '11.0.x' + phpstan: '1' steps: - name: Checkout Drupal core uses: actions/checkout@v4 From f876dc0cc4ddbcfa17437742862ede8035277722 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Mon, 17 Jun 2024 13:26:11 +0530 Subject: [PATCH 03/18] Update github workflow and dataProviders with static. --- .github/workflows/testing.yml | 7 ++++--- 1 | 19 +++++++++++++++++++ .../DataProducer/EntityReferenceTest.php | 2 +- .../Images/ImageResourceUrlTest.php | 2 +- tests/src/Kernel/DataProducer/SeekTest.php | 2 +- tests/src/Kernel/DataProducer/StringTest.php | 2 +- tests/src/Kernel/Framework/CsrfTest.php | 6 +++--- .../Kernel/Framework/PersistedQueriesTest.php | 2 +- tests/src/Kernel/ResolverBuilderTest.php | 2 +- 9 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 1 diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b9af5b829..14bbf1b74 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -89,10 +89,11 @@ jobs: composer --no-interaction run-script drupal-phpunit-upgrade composer config --no-plugins allow-plugins.phpstan/extension-installer true + # Revisit - check for latest release of dependent modules. - name: Install GraphQL dependencies run: | composer --no-interaction --no-progress require \ - webonyx/graphql-php:^14.8 \ + webonyx/graphql-php:^15.12 \ drupal/typed_data:^1.0 \ drupal/redirect:^1.0 @@ -112,8 +113,8 @@ jobs: mglaman/phpstan-drupal:^1.1.2 \ phpstan/phpstan-deprecation-rules:^1.0.0 \ jangregor/phpstan-prophecy:^1.0.0 \ - phpstan/phpstan-phpunit:^1.0.0 \ - phpstan/extension-installer:^1.0 + phpstan/phpstan-phpunit:^1.4 \ + phpstan/extension-installer:^1.4 composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.24 - name: Run PHPStan diff --git a/1 b/1 new file mode 100644 index 000000000..5b8c9180d --- /dev/null +++ b/1 @@ -0,0 +1,19 @@ +Update github workflow to ready for drupal next minor and major version. + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# Author: Ankit Pathak <106175376+apathak18@users.noreply.github.com> +# +# interactive rebase in progress; onto 75dd0a4 +# Last commands done (2 commands done): +# pick 6515b02 Drupal 11 readiness. +# pick 8c2bcaf Update github workflow to ready for drupal next minor and major version. +# Next commands to do (2 remaining commands): +# pick 14bba39 Update github workflow and dataProviders with static. +# pick c456f77 Adding minimum php version 8.0 and included typed_data module. +# You are currently rebasing branch '8.x-4.x' on '75dd0a4'. +# +# Changes to be committed: +# modified: .github/workflows/testing.yml +# diff --git a/tests/src/Kernel/DataProducer/EntityReferenceTest.php b/tests/src/Kernel/DataProducer/EntityReferenceTest.php index bb3a8cc40..bfe0c78b4 100644 --- a/tests/src/Kernel/DataProducer/EntityReferenceTest.php +++ b/tests/src/Kernel/DataProducer/EntityReferenceTest.php @@ -136,7 +136,7 @@ public function testEmptyResults(string $data_producer, array $contexts): void { /** * Data provider for testEmptyResults(). */ - public function emptyResultsProvider(): array { + public static function emptyResultsProvider(): array { return [ // Test that an empty reference field returns an empty array. ['entity_reference', [ diff --git a/tests/src/Kernel/DataProducer/Images/ImageResourceUrlTest.php b/tests/src/Kernel/DataProducer/Images/ImageResourceUrlTest.php index ca2d40b85..4abbe3c0a 100644 --- a/tests/src/Kernel/DataProducer/Images/ImageResourceUrlTest.php +++ b/tests/src/Kernel/DataProducer/Images/ImageResourceUrlTest.php @@ -27,7 +27,7 @@ public function testImageResourceUrl(array $input, string $expected): void { /** * Provider for testImageResourceUrl(). */ - public function imageResourceUrlProvider(): array { + public static function imageResourceUrlProvider(): array { return [ [ ['url' => 'http://localhost/test_image.jpg'], diff --git a/tests/src/Kernel/DataProducer/SeekTest.php b/tests/src/Kernel/DataProducer/SeekTest.php index e31dbf885..f4c45ffba 100644 --- a/tests/src/Kernel/DataProducer/SeekTest.php +++ b/tests/src/Kernel/DataProducer/SeekTest.php @@ -37,7 +37,7 @@ public function testSeek(array $input, int $position, $expected): void { * * @return array */ - public function seekProvider(): array { + public static function seekProvider(): array { return [ [ [1, 2, 3], diff --git a/tests/src/Kernel/DataProducer/StringTest.php b/tests/src/Kernel/DataProducer/StringTest.php index d82f522d3..4184f11e5 100644 --- a/tests/src/Kernel/DataProducer/StringTest.php +++ b/tests/src/Kernel/DataProducer/StringTest.php @@ -27,7 +27,7 @@ public function testUppercase(string $input, string $expected): void { /** * Tests the upper case data producer. */ - public function uppercaseProvider(): array { + public static function uppercaseProvider(): array { return [ ['test', 'TEST'], ['123 ..!!', '123 ..!!'], diff --git a/tests/src/Kernel/Framework/CsrfTest.php b/tests/src/Kernel/Framework/CsrfTest.php index 34d451b30..61ca2e33a 100644 --- a/tests/src/Kernel/Framework/CsrfTest.php +++ b/tests/src/Kernel/Framework/CsrfTest.php @@ -64,7 +64,7 @@ public function testEvilOrigin(string $content_type): void { /** * Data provider for testContentTypeCsrf(). */ - public function provideSimpleContentTypes(): array { + public static function provideSimpleContentTypes(): array { // Three content types that can be sent with simple no-cors POST requests. return [ ['text/plain'], @@ -115,7 +115,7 @@ public function testAllowedJsonRequests(array $headers): void { /** * Data provider for testAllowedJsonRequests(). */ - public function provideAllowedJsonHeaders(): array { + public static function provideAllowedJsonHeaders(): array { return [ [['CONTENT_TYPE' => 'application/json']], [['CONTENT_TYPE' => 'application/graphql']], @@ -149,7 +149,7 @@ public function testAllowedFormRequests(array $headers, array $allowedDomains = /** * Data provider for testAllowedFormRequests(). */ - public function provideAllowedFormRequests(): array { + public static function provideAllowedFormRequests(): array { return [ // Omitting the Origin and Apollo-Require-Preflight is allowed. [['CONTENT_TYPE' => 'multipart/form-data']], diff --git a/tests/src/Kernel/Framework/PersistedQueriesTest.php b/tests/src/Kernel/Framework/PersistedQueriesTest.php index e28e0b5d9..7958d7f0c 100644 --- a/tests/src/Kernel/Framework/PersistedQueriesTest.php +++ b/tests/src/Kernel/Framework/PersistedQueriesTest.php @@ -75,7 +75,7 @@ public function testPersistedQueries(array $instanceIds, string $queryId, array /** * Data provider for testPersistedQueries(). */ - public function persistedQueriesDataProvider(): array { + public static function persistedQueriesDataProvider(): array { return [ // This is the most usual case, all the three plugins are enabled. [ diff --git a/tests/src/Kernel/ResolverBuilderTest.php b/tests/src/Kernel/ResolverBuilderTest.php index d800923fe..8fb178e87 100644 --- a/tests/src/Kernel/ResolverBuilderTest.php +++ b/tests/src/Kernel/ResolverBuilderTest.php @@ -62,7 +62,7 @@ public function testBuilderProducing($input, $expected): void { /** * @return array */ - public function builderProducingProvider(): array { + public static function builderProducingProvider(): array { return [ ['entity_load', ResolverInterface::class], ['entity_id', ResolverInterface::class], From 8b821ae4c3b3d9a16fbfb3c7d4a833119583c8e9 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Mon, 17 Jun 2024 16:28:00 +0530 Subject: [PATCH 04/18] Adding minimum php version 8.0 and included typed_data module. --- .github/workflows/testing.yml | 4 ++-- 1 | 19 ------------------- composer.json | 5 +++-- 3 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 1 diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 14bbf1b74..6de88b533 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -94,8 +94,8 @@ jobs: run: | composer --no-interaction --no-progress require \ webonyx/graphql-php:^15.12 \ - drupal/typed_data:^1.0 \ - drupal/redirect:^1.0 + drupal/typed_data:^2.0 \ + drupal/redirect:dev-1.x - name: Run PHPUnit run: | diff --git a/1 b/1 deleted file mode 100644 index 5b8c9180d..000000000 --- a/1 +++ /dev/null @@ -1,19 +0,0 @@ -Update github workflow to ready for drupal next minor and major version. - -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit. -# -# Author: Ankit Pathak <106175376+apathak18@users.noreply.github.com> -# -# interactive rebase in progress; onto 75dd0a4 -# Last commands done (2 commands done): -# pick 6515b02 Drupal 11 readiness. -# pick 8c2bcaf Update github workflow to ready for drupal next minor and major version. -# Next commands to do (2 remaining commands): -# pick 14bba39 Update github workflow and dataProviders with static. -# pick c456f77 Adding minimum php version 8.0 and included typed_data module. -# You are currently rebasing branch '8.x-4.x' on '75dd0a4'. -# -# Changes to be committed: -# modified: .github/workflows/testing.yml -# diff --git a/composer.json b/composer.json index e3c4620da..063f35601 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,9 @@ "homepage": "http://drupal.org/project/graphql", "license": "GPL-2.0+", "require": { - "php": ">=7.3", - "webonyx/graphql-php": "^14.8.0" + "drupal/typed_data": "^1.0 || ^2.0", + "php": ">=8.0", + "webonyx/graphql-php": "^15.12.0" }, "minimum-stability": "dev" } From a486fc91a73108f7f8d78c3165fedaef6655845c Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Thu, 18 Jul 2024 22:58:45 +0530 Subject: [PATCH 05/18] Attempt to fix the tests and adding both version for webonyx/graphql-php. --- .github/workflows/testing.yml | 2 +- composer.json | 2 +- tests/src/Kernel/DataProducer/DefaultValueTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 6de88b533..07cfec292 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -93,7 +93,7 @@ jobs: - name: Install GraphQL dependencies run: | composer --no-interaction --no-progress require \ - webonyx/graphql-php:^15.12 \ + webonyx/graphql-php:^14.8 \ drupal/typed_data:^2.0 \ drupal/redirect:dev-1.x diff --git a/composer.json b/composer.json index 063f35601..b1527772d 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "require": { "drupal/typed_data": "^1.0 || ^2.0", "php": ">=8.0", - "webonyx/graphql-php": "^15.12.0" + "webonyx/graphql-php": "^14.8.0" }, "minimum-stability": "dev" } diff --git a/tests/src/Kernel/DataProducer/DefaultValueTest.php b/tests/src/Kernel/DataProducer/DefaultValueTest.php index 2185d2e7b..7e459e088 100644 --- a/tests/src/Kernel/DataProducer/DefaultValueTest.php +++ b/tests/src/Kernel/DataProducer/DefaultValueTest.php @@ -54,7 +54,7 @@ public function testLegacyDefaultValueSetting(bool $populate_setting, string $te /** * Data provider for the testLegacyDefaultValueSetting test. */ - public function settingsProvider(): array { + public static function settingsProvider(): array { return [ [FALSE, TestLegacyEntityLoad::class], [TRUE, TestNewEntityLoad::class], From e3037c18fe1c090d722a56b8832e200ddfc820e1 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 19 Jul 2024 16:34:03 +0530 Subject: [PATCH 06/18] Updated with ubuntu 24.04 --- .github/workflows/testing.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 07cfec292..549aa64da 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -7,7 +7,7 @@ on: jobs: drupal: name: Drupal ${{ matrix.drupal-core }} (PHP ${{ matrix.php-versions }}) - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 env: extensions: mbstring, xml, pdo_sqlite, gd, opcache strategy: diff --git a/composer.json b/composer.json index b1527772d..2db50bd0a 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license": "GPL-2.0+", "require": { "drupal/typed_data": "^1.0 || ^2.0", - "php": ">=8.0", + "php": ">=8.1", "webonyx/graphql-php": "^14.8.0" }, "minimum-stability": "dev" From f8f6d1359fff952665dfb782a6612eb6e8998247 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Sun, 21 Jul 2024 16:16:27 +0530 Subject: [PATCH 07/18] Bumping to D10.2 and fixing deprecation removed from D11. --- .github/workflows/testing.yml | 22 ++--- .../graphql_composable.info.yml | 2 +- .../graphql_example/graphql_examples.info.yml | 2 +- graphql.info.yml | 2 +- graphql.services.yml | 1 + src/GraphQL/Response/Response.php | 2 +- src/GraphQL/Response/ResponseInterface.php | 6 +- src/GraphQL/Utility/FileUpload.php | 96 ++++++++++--------- tests/src/Kernel/AlterableSchemaTest.php | 1 - .../Framework/UploadFileServiceTest.php | 11 ++- tests/src/Kernel/GraphQLTestBase.php | 2 + 11 files changed, 76 insertions(+), 71 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 549aa64da..6f758a8a8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,22 +13,18 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['8.1', '8.2'] - drupal-core: ['10.3.x'] - phpstan: ['0'] + # # php-versions: ['8.1', '8.2'] + # # drupal-core: ['10.3.x'] + # phpstan: ['0'] include: - # Extra run to test older supported Drupal 10.1.x. - - php-versions: '8.1' - drupal-core: '10.1.x' - phpstan: '0' # Extra run to test older supported Drupal 10.2.x. - - php-versions: '8.1' - drupal-core: '10.2.x' - phpstan: '0' + # - php-versions: '8.1' + # drupal-core: '10.2.x' + # phpstan: '0' # We only need to run PHPStan once on the latest PHP version. - - php-versions: '8.3' - drupal-core: '10.3.x' - phpstan: '1' + # - php-versions: '8.3' + # drupal-core: '10.3.x' + # phpstan: '1' - php-versions: '8.3' drupal-core: '11.0.x' phpstan: '1' diff --git a/examples/graphql_composable/graphql_composable.info.yml b/examples/graphql_composable/graphql_composable.info.yml index a891052cb..08add43f5 100644 --- a/examples/graphql_composable/graphql_composable.info.yml +++ b/examples/graphql_composable/graphql_composable.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^10.1 || ^11 +core_version_requirement: ^10.2 || ^11 diff --git a/examples/graphql_example/graphql_examples.info.yml b/examples/graphql_example/graphql_examples.info.yml index 8587aa2e8..4f03a1abe 100644 --- a/examples/graphql_example/graphql_examples.info.yml +++ b/examples/graphql_example/graphql_examples.info.yml @@ -5,4 +5,4 @@ package: GraphQL dependencies: - graphql:graphql - node:node -core_version_requirement: ^10.1 || ^11 +core_version_requirement: ^10.2 || ^11 diff --git a/graphql.info.yml b/graphql.info.yml index 90852febe..8b43f0087 100644 --- a/graphql.info.yml +++ b/graphql.info.yml @@ -3,6 +3,6 @@ type: module description: 'Base module for integrating GraphQL with Drupal.' package: GraphQL configure: graphql.config_page -core_version_requirement: ^10.1 || ^11 +core_version_requirement: ^10.2 || ^11 dependencies: - typed_data:typed_data diff --git a/graphql.services.yml b/graphql.services.yml index ad0c2c9a7..23c01419f 100644 --- a/graphql.services.yml +++ b/graphql.services.yml @@ -184,6 +184,7 @@ services: - '@renderer' - '@event_dispatcher' - '@image.factory' + - '@file.validator' plugin.manager.graphql.persisted_query: class: Drupal\graphql\Plugin\PersistedQueryPluginManager diff --git a/src/GraphQL/Response/Response.php b/src/GraphQL/Response/Response.php index 20b2c4eff..4467445bc 100644 --- a/src/GraphQL/Response/Response.php +++ b/src/GraphQL/Response/Response.php @@ -27,7 +27,7 @@ public function addViolation($message, array $properties = []): void { /** * {@inheritdoc} */ - public function addViolations(array $messages, array $properties = []): void { + public function addViolations($messages, array $properties = []): void { foreach ($messages as $message) { $this->addViolation($message, $properties); } diff --git a/src/GraphQL/Response/ResponseInterface.php b/src/GraphQL/Response/ResponseInterface.php index f8f050ab0..f83eda7c7 100644 --- a/src/GraphQL/Response/ResponseInterface.php +++ b/src/GraphQL/Response/ResponseInterface.php @@ -12,7 +12,7 @@ interface ResponseInterface { /** * Adds the violation. * - * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $message + * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup|\Symfony\Component\Validator\ConstraintViolationListInterface $message * Violation message. * @param array $properties * Other properties related to the violation. @@ -22,12 +22,12 @@ public function addViolation($message, array $properties = []): void; /** * Adds multiple violations. * - * @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] $messages + * @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[]|\Symfony\Component\Validator\ConstraintViolationListInterface $messages * Violation messages. * @param array $properties * Other properties related to the violation. */ - public function addViolations(array $messages, array $properties = []): void; + public function addViolations(array|ConstraintViolationListInterface $messages, array $properties = []): void; /** * Gets the violations. diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 7543ea5c7..26ddfba0e 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -17,9 +17,11 @@ use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Core\StringTranslation\ByteSizeMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; use Drupal\file\FileInterface; +use Drupal\file\Validation\FileValidatorInterface; use Drupal\graphql\GraphQL\Response\FileUploadResponse; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -37,7 +39,7 @@ class FileUpload { /** * The file storage where we will create new file entities from. * - * @var \Drupal\file\FileStorageInterface + * @var \Drupal\Core\Entity\EntityStorageInterface */ protected $fileStorage; @@ -111,6 +113,13 @@ class FileUpload { */ protected $imageFactory; + /** + * The file validator service. + * + * @var \Drupal\file\Validation\FileValidatorInterface + */ + protected FileValidatorInterface $fileValidator; + /** * Constructor. */ @@ -126,10 +135,9 @@ public function __construct( RendererInterface $renderer, EventDispatcherInterface $eventDispatcher, ImageFactory $image_factory, + FileValidatorInterface $file_validator, ) { - /** @var \Drupal\file\FileStorageInterface $file_storage */ - $file_storage = $entityTypeManager->getStorage('file'); - $this->fileStorage = $file_storage; + $this->fileStorage = $entityTypeManager->getStorage('file'); $this->currentUser = $currentUser; $this->mimeTypeGuesser = $mimeTypeGuesser; $this->fileSystem = $fileSystem; @@ -140,6 +148,7 @@ public function __construct( $this->renderer = $renderer; $this->eventDispatcher = $eventDispatcher; $this->imageFactory = $image_factory; + $this->fileValidator = $file_validator; } /** @@ -193,10 +202,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi switch ($uploaded_file->getError()) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: - // @todo Drupal 10.1 compatibility, needs to be converted to - // ByteSizeMarkup later. - // @phpstan-ignore-next-line - $maxUploadSize = format_size($this->getMaxUploadSize($settings)); + $maxUploadSize = ByteSizeMarkup::create($this->getMaxUploadSize($settings)); $response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [ '@file' => $uploaded_file->getClientOriginalName(), '@maxsize' => $maxUploadSize, @@ -248,8 +254,8 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi $temp_file_path = $uploaded_file->getRealPath(); - // Drupal 10.2 compatibility: use the deprecated constant for now. - // @phpstan-ignore-next-line + // Drupal 10.3 compatibility: use the deprecated constant for now. + // @phpstan-ignore-next-line as it is deprecated in D12. $file_uri = $this->fileSystem->getDestinationFilename($file_uri, FileSystemInterface::EXISTS_RENAME); // Lock based on the prepared file URI. @@ -262,7 +268,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi try { // Begin building file entity. - /** @var \Drupal\file\FileInterface $file */ + /** @var \Drupal\Core\Entity\EntityInterface $file */ $file = $this->fileStorage->create([]); $file->setOwnerId($this->currentUser->id()); $file->setFilename($prepared_filename); @@ -272,29 +278,31 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi // before it is saved. $file->setSize(@filesize($temp_file_path)); - // Validate against file_validate() first with the temporary path. - // @todo Drupal 10.1 compatibility, needs to be converted to file validate - // service later. - // @phpstan-ignore-next-line - $errors = file_validate($file, $validators); - $maxResolution = $settings['max_resolution'] ?? 0; - $minResolution = $settings['min_resolution'] ?? 0; - if (!empty($maxResolution) || !empty($minResolution)) { - $errors += $this->validateFileImageResolution($file, $maxResolution, $minResolution); - } - + // Validate against fileValidator first with the temporary path. + /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */ + $errors = $this->fileValidator->validate($file, $validators); if (!empty($errors)) { $response->addViolations($errors); return $response; } + // Validate Image resolution. + $maxResolution = $settings['max_resolution'] ?? 0; + $minResolution = $settings['min_resolution'] ?? 0; + if (!empty($maxResolution) || !empty($minResolution)) { + $image_resolution_errors = $this->validateFileImageResolution($file, $maxResolution, $minResolution); + if (!empty($image_resolution_errors)) { + $response->addViolations($image_resolution_errors); + return $response; + } + } $file->setFileUri($file_uri); // Move the file to the correct location after validation. Use // FileSystemInterface::EXISTS_ERROR as the file location has already been // determined above in FileSystem::getDestinationFilename(). try { - // Drupal 10.2 compatibility: use the deprecated constant for now. - // @phpstan-ignore-next-line + // Drupal 10.3 compatibility: use the deprecated constant for now. + // @phpstan-ignore-next-line as it is deprecated in D12. $this->fileSystem->move($temp_file_path, $file_uri, FileSystemInterface::EXISTS_ERROR); } catch (FileException $e) { @@ -487,12 +495,12 @@ protected function validateFileImageResolution(FileInterface $file, $maximum_dim protected function prepareFilename(string $filename, array &$validators): string { // Don't rename if 'allow_insecure_uploads' evaluates to TRUE. if (!$this->systemFileConfig->get('allow_insecure_uploads')) { - if (!empty($validators['file_validate_extensions'][0])) { - // If there is a file_validate_extensions validator and a list of - // valid extensions, munge the filename to protect against possible - // malicious extension hiding within an unknown file type. For example, - // "filename.html.foo". - $event = new FileUploadSanitizeNameEvent($filename, $validators['file_validate_extensions'][0]); + if (!empty($validators['FileExtension']['extensions'])) { + // If there is a fileValidator service to validate FileExtension and + // a list of valid extensions, munge the filename to protect against + // possible malicious extension hiding within an unknown file type. + // For example, "filename.html.foo". + $event = new FileUploadSanitizeNameEvent($filename, $validators['FileExtension']['extensions']); $this->eventDispatcher->dispatch($event); $filename = $event->getFilename(); } @@ -502,33 +510,31 @@ protected function prepareFilename(string $filename, array &$validators): string // and filename._php.txt, respectively). if (preg_match(FileSystemInterface::INSECURE_EXTENSION_REGEX, $filename)) { // If the file will be rejected anyway due to a disallowed extension, it - // should not be renamed; rather, we'll let file_validate_extensions() - // reject it below. + // should not be renamed; rather, we'll let fileValidator service + // to validate FileExtension reject it below. + $passes_validation = FALSE; - if (!empty($validators['file_validate_extensions'][0])) { - /** @var \Drupal\file\FileInterface $file */ + if (!empty($validators['FileExtension']['extensions'])) { + /** @var \Drupal\Core\Entity\EntityInterface $file */ $file = $this->fileStorage->create([]); $file->setFilename($filename); - // @todo Drupal 10.1 compatibility, needs to be converted to file - // validator service later. - // @phpstan-ignore-next-line - $passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0])); + $passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); } - if (empty($validators['file_validate_extensions'][0]) || $passes_validation) { + if (empty($validators['FileExtension']['extensions']) || $passes_validation) { if ((substr($filename, -4) != '.txt')) { // The destination filename will also later be used to create the // URI. $filename .= '.txt'; } - $event = new FileUploadSanitizeNameEvent($filename, $validators['file_validate_extensions'][0] ?? ''); + $event = new FileUploadSanitizeNameEvent($filename, $validators['FileExtension']['extensions'] ?? ''); $this->eventDispatcher->dispatch($event); $filename = $event->getFilename(); // The .txt extension may not be in the allowed list of extensions. We // have to add it here or else the file upload will fail. - if (!empty($validators['file_validate_extensions'][0])) { - $validators['file_validate_extensions'][0] .= ' txt'; + if (!empty($validators['FileExtension']['extensions'])) { + $validators['FileExtension']['extensions'] .= ' txt'; } } } @@ -579,7 +585,7 @@ protected function getUploadLocation(array $settings): string { protected function getUploadValidators(array $settings): array { $validators = [ // Add in our check of the file name length. - 'file_validate_name_length' => [], + 'FileNameLength' => [], ]; // Cap the upload size according to the PHP limit. @@ -589,11 +595,11 @@ protected function getUploadValidators(array $settings): array { } // There is always a file size limit due to the PHP server limit. - $validators['file_validate_size'] = [$max_filesize]; + $validators['FileSizeLimit'] = ['fileLimit' => $max_filesize]; // Add the extension check if necessary. if (!empty($settings['file_extensions'])) { - $validators['file_validate_extensions'] = [$settings['file_extensions']]; + $validators['FileExtension'] = ['extensions' => $settings['file_extensions']]; } return $validators; diff --git a/tests/src/Kernel/AlterableSchemaTest.php b/tests/src/Kernel/AlterableSchemaTest.php index 961e46645..e8ba6bc58 100644 --- a/tests/src/Kernel/AlterableSchemaTest.php +++ b/tests/src/Kernel/AlterableSchemaTest.php @@ -154,7 +154,6 @@ protected function mockSchema($id, $schema, array $extensions = []): void { $extensions['graphql_alterable_schema_test']->expects(static::any()) ->method('getBaseDefinition') ->willReturn(''); - // Different extension definition for different tests. // PHPUnit compatibility: remove once support for Drupal 10.2 is dropped. $methodName = method_exists($this, 'name') ? 'name' : 'getName'; diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index 79ddf8c2c..c0307bd6b 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -104,7 +104,7 @@ public function testPartialFile(): void { ]); $violations = $file_upload_response->getViolations(); - $this->assertStringMatchesFormat( + $this->assertStringContainsString( 'The file "test.txt" could not be saved because the upload did not complete.', $violations[0]['message'] ); @@ -140,7 +140,7 @@ public function testSizeValidation(): void { $violations = $file_upload_response->getViolations(); // @todo Do we want HTML tags in our violations or not? - $this->assertStringMatchesFormat( + $this->assertStringContainsString( 'The file is 4 bytes exceeding the maximum file size of 1 byte.', $violations[0]['message'] ); @@ -190,7 +190,7 @@ public function testDimensionTooSmallValidation(): void { ]); $violations = $file_upload_response->getViolations(); - $this->assertStringMatchesFormat( + $this->assertStringContainsString( 'The image is too small. The minimum dimensions are 15x15 pixels and the image size is 10x10 pixels.', $violations[0]['message'] ); @@ -228,7 +228,7 @@ public function testExtensionValidation(): void { $violations = $file_upload_response->getViolations(); // @todo Do we want HTML tags in our violations or not? - $this->assertStringMatchesFormat( + $this->assertStringContainsString( 'Only files with the following extensions are allowed: odt.', $violations[0]['message'] ); @@ -256,6 +256,7 @@ public function testLockReleased(): void { \Drupal::service('renderer'), \Drupal::service('event_dispatcher'), \Drupal::service('image.factory'), + \Drupal::service('file.validator'), ); // Create a Symfony dummy uploaded file in test mode. @@ -319,7 +320,7 @@ public function testUnsuccessWithMultipleFileUploads(): void { // There must be violation regarding forbidden file extension. $violations = $file_upload_response->getViolations(); - $this->assertStringMatchesFormat( + $this->assertStringContainsString( 'Only files with the following extensions are allowed: txt.', $violations[0]['message'] ); diff --git a/tests/src/Kernel/GraphQLTestBase.php b/tests/src/Kernel/GraphQLTestBase.php index 20425566f..e529215c5 100644 --- a/tests/src/Kernel/GraphQLTestBase.php +++ b/tests/src/Kernel/GraphQLTestBase.php @@ -50,6 +50,7 @@ abstract class GraphQLTestBase extends KernelTestBase { 'content_translation', 'entity_reference_test', 'field', + 'file', 'menu_link_content', 'link', 'typed_data', @@ -75,6 +76,7 @@ protected function setUp(): void { $this->installEntitySchema('graphql_server'); $this->installEntitySchema('configurable_language'); $this->installConfig(['language']); + $this->installEntitySchema('file'); $this->installEntitySchema('menu_link_content'); $this->setUpCurrentUser([], $this->userPermissions()); From 11ddd6fa113b4a9b730a620ad1cbab347faa9cfe Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Thu, 25 Jul 2024 19:46:54 +0530 Subject: [PATCH 08/18] Removing hook_file_validate test module. --- .github/workflows/testing.yml | 18 +++++++++--------- src/EventSubscriber/SubrequestSubscriber.php | 2 +- src/GraphQL/Utility/FileUpload.php | 16 +++++++++------- .../graphql_file_validate.info.yml | 5 ----- .../graphql_file_validate.module | 17 ----------------- tests/src/Kernel/AlterableSchemaTest.php | 12 ++---------- .../Kernel/Framework/UploadFileServiceTest.php | 13 +++++++------ 7 files changed, 28 insertions(+), 55 deletions(-) delete mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.info.yml delete mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.module diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 6f758a8a8..452c23cf7 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,18 +13,18 @@ jobs: strategy: fail-fast: false matrix: - # # php-versions: ['8.1', '8.2'] - # # drupal-core: ['10.3.x'] - # phpstan: ['0'] + php-versions: ['8.1', '8.2'] + drupal-core: ['10.3.x'] + phpstan: ['0'] include: # Extra run to test older supported Drupal 10.2.x. - # - php-versions: '8.1' - # drupal-core: '10.2.x' - # phpstan: '0' + - php-versions: '8.1' + drupal-core: '10.2.x' + phpstan: '0' # We only need to run PHPStan once on the latest PHP version. - # - php-versions: '8.3' - # drupal-core: '10.3.x' - # phpstan: '1' + - php-versions: '8.3' + drupal-core: '10.3.x' + phpstan: '1' - php-versions: '8.3' drupal-core: '11.0.x' phpstan: '1' diff --git a/src/EventSubscriber/SubrequestSubscriber.php b/src/EventSubscriber/SubrequestSubscriber.php index 7466a4a64..bf09068a4 100644 --- a/src/EventSubscriber/SubrequestSubscriber.php +++ b/src/EventSubscriber/SubrequestSubscriber.php @@ -67,7 +67,7 @@ public function onKernelRequestFinished(FinishRequestEvent $event): void { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => 'onKernelRequest', KernelEvents::FINISH_REQUEST => 'onKernelRequestFinished', diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 26ddfba0e..d2d38f4ca 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -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; @@ -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; @@ -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); @@ -281,10 +283,11 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi // Validate against fileValidator first with the temporary path. /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */ $errors = $this->fileValidator->validate($file, $validators); - if (!empty($errors)) { + if (count($errors) > 0) { $response->addViolations($errors); return $response; } + // Validate Image resolution. $maxResolution = $settings['max_resolution'] ?? 0; $minResolution = $settings['min_resolution'] ?? 0; @@ -323,7 +326,6 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi } $file->save(); - $response->setFileEntity($file); return $response; } @@ -515,7 +517,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'])); diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml deleted file mode 100644 index 1443533b4..000000000 --- a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml +++ /dev/null @@ -1,5 +0,0 @@ -type: module -name: GraphQL File Validate Test -description: Tests hook_file_validate() on uploads. -package: Testing -hidden: TRUE diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.module b/tests/modules/graphql_file_validate/graphql_file_validate.module deleted file mode 100644 index ae89684be..000000000 --- a/tests/modules/graphql_file_validate/graphql_file_validate.module +++ /dev/null @@ -1,17 +0,0 @@ -getFileUri())) { - throw new \Exception('File does not exist during validation: ' . $file->getFileUri()); - } -} diff --git a/tests/src/Kernel/AlterableSchemaTest.php b/tests/src/Kernel/AlterableSchemaTest.php index e8ba6bc58..c77c4aaa5 100644 --- a/tests/src/Kernel/AlterableSchemaTest.php +++ b/tests/src/Kernel/AlterableSchemaTest.php @@ -114,9 +114,9 @@ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded(): void $this->assertSame([ 'errors' => [ 0 => [ - 'message' => 'Internal server error', + 'message' => 'Cannot query field "empty" on type "Result".', 'extensions' => [ - 'category' => 'internal', + 'category' => 'graphql', ], 'locations' => [ 0 => [ @@ -124,16 +124,8 @@ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded(): void 'column' => 37, ], ], - 'path' => [ - 'alterableQuery', - // Reference to our variable in the error. - 'empty', - ], ], ], - 'data' => [ - 'alterableQuery' => NULL, - ], ], json_decode($result->getContent(), TRUE)); } diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index c0307bd6b..ae2b864ed 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -15,11 +15,6 @@ */ class UploadFileServiceTest extends GraphQLTestBase { - /** - * {@inheritdoc} - */ - protected static $modules = ['file', 'graphql_file_validate']; - /** * The FileUpload object we want to test, gets prepared in setUp(). * @@ -27,6 +22,13 @@ class UploadFileServiceTest extends GraphQLTestBase { */ protected $uploadService; + /** + * Modules to enable. + * + * @var array + */ + protected static $modules = ['file']; + /** * Gets the file path of the source file. * @@ -67,7 +69,6 @@ public function testSuccess(): void { 'file_directory' => 'test', ]); $file_entity = $file_upload_response->getFileEntity(); - $this->assertSame('public://test/test.txt', $file_entity->getFileUri()); $this->assertFileExists($file_entity->getFileUri()); } From ca6582296e59135286f2ceb813369bda114d4ba2 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Thu, 25 Jul 2024 23:18:43 +0530 Subject: [PATCH 09/18] Fixing phpstan issues. --- src/EventSubscriber/ApqSubscriber.php | 2 +- src/EventSubscriber/OperationSubscriber.php | 2 +- src/GraphQL/Response/ResponseInterface.php | 2 ++ src/GraphQL/Utility/FileUpload.php | 4 ++-- tests/src/Kernel/Framework/UploadFileServiceTest.php | 7 ------- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/EventSubscriber/ApqSubscriber.php b/src/EventSubscriber/ApqSubscriber.php index ada2b53dd..0dcd364e5 100644 --- a/src/EventSubscriber/ApqSubscriber.php +++ b/src/EventSubscriber/ApqSubscriber.php @@ -65,7 +65,7 @@ public function onBeforeOperation(OperationEvent $event): void { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ OperationEvent::GRAPHQL_OPERATION_BEFORE => 'onBeforeOperation', ]; diff --git a/src/EventSubscriber/OperationSubscriber.php b/src/EventSubscriber/OperationSubscriber.php index a79cd94ba..989f07e85 100644 --- a/src/EventSubscriber/OperationSubscriber.php +++ b/src/EventSubscriber/OperationSubscriber.php @@ -73,7 +73,7 @@ public function onAfterOperation(OperationEvent $event): void { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { + public static function getSubscribedEvents(): array { return [ OperationEvent::GRAPHQL_OPERATION_BEFORE => 'onBeforeOperation', OperationEvent::GRAPHQL_OPERATION_AFTER => 'onAfterOperation', diff --git a/src/GraphQL/Response/ResponseInterface.php b/src/GraphQL/Response/ResponseInterface.php index f83eda7c7..eba425edf 100644 --- a/src/GraphQL/Response/ResponseInterface.php +++ b/src/GraphQL/Response/ResponseInterface.php @@ -4,6 +4,8 @@ namespace Drupal\graphql\GraphQL\Response; +use Symfony\Component\Validator\ConstraintViolationListInterface; + /** * Response interface used for GraphQL responses. */ diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index d2d38f4ca..7d1aff08c 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -520,9 +520,9 @@ protected function prepareFilename(string $filename, array &$validators): string /** @var \Drupal\file\FileInterface $file */ $file = $this->fileStorage->create([]); $file->setFilename($filename); - $passes_validation = empty($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); + $passes_validation = count($this->fileValidator->validate($file, $validators['FileExtension']['extensions'])); } - if (empty($validators['FileExtension']['extensions']) || $passes_validation) { + if (empty($validators['FileExtension']['extensions']) || ($passes_validation > 0)) { if ((substr($filename, -4) != '.txt')) { // The destination filename will also later be used to create the // URI. diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index ae2b864ed..dffb9c3a2 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -22,13 +22,6 @@ class UploadFileServiceTest extends GraphQLTestBase { */ protected $uploadService; - /** - * Modules to enable. - * - * @var array - */ - protected static $modules = ['file']; - /** * Gets the file path of the source file. * From 5f2eeecb791005c5e4f58f26a41448c555a4d367 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 26 Jul 2024 00:32:06 +0530 Subject: [PATCH 10/18] Fixing remaining phpstan warnings. --- src/Routing/QueryRouteEnhancer.php | 1 - .../Fields/Image/ImageDerivativeTest.php | 5 ---- .../DataProducer/EntityReferenceTest.php | 25 +------------------ tests/src/Traits/MockingTrait.php | 7 +++--- 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/Routing/QueryRouteEnhancer.php b/src/Routing/QueryRouteEnhancer.php index 079f90e49..ae063b4f9 100644 --- a/src/Routing/QueryRouteEnhancer.php +++ b/src/Routing/QueryRouteEnhancer.php @@ -92,7 +92,6 @@ protected function assertValidPostRequestHeaders(Request $request) : void { return; } - // @phpstan-ignore-next-line $content_format = method_exists($request, 'getContentTypeFormat') ? $request->getContentTypeFormat() : $request->getContentType(); if ($content_format === NULL) { // Symfony before 5.4 does not detect "multipart/form-data", check for it diff --git a/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php b/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php index 18ef12b7c..375fff3ae 100644 --- a/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php +++ b/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php @@ -62,11 +62,6 @@ public function setUp(): void { $this->file->method('getFileUri')->willReturn($this->fileUri); $this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag'])); - // @todo Remove hard-coded properties and only rely on image factory. - // @phpstan-ignore-next-line - @$this->file->width = 600; - // @phpstan-ignore-next-line - @$this->file->height = 400; $this->style = ImageStyle::create(['name' => 'test_style']); $effect = [ diff --git a/tests/src/Kernel/DataProducer/EntityReferenceTest.php b/tests/src/Kernel/DataProducer/EntityReferenceTest.php index bfe0c78b4..3b7700eff 100644 --- a/tests/src/Kernel/DataProducer/EntityReferenceTest.php +++ b/tests/src/Kernel/DataProducer/EntityReferenceTest.php @@ -6,31 +6,8 @@ use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\graphql\Kernel\GraphQLTestBase; +use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; -// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1. -if (strpos(\Drupal::VERSION, '10.1') === 0) { - - /** - * Helper trait for compatibility with Drupal 9. - * - * @phpcs:disable Drupal.Classes.ClassFileName.NoMatch - */ - trait EntityReferenceFieldCreationTrait { - // @phpstan-ignore-next-line - use \Drupal\Tests\field\Traits\EntityReferenceTestTrait; - - } -} -else { - - /** - * Helper trait for compatibility with Drupal 10. - */ - trait EntityReferenceFieldCreationTrait { - use \Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; - - } -} /** * Tests the entity_reference data producers. diff --git a/tests/src/Traits/MockingTrait.php b/tests/src/Traits/MockingTrait.php index b45077e15..1770ffc0e 100644 --- a/tests/src/Traits/MockingTrait.php +++ b/tests/src/Traits/MockingTrait.php @@ -53,6 +53,7 @@ trait MockingTrait { * The return callback promise. */ protected function toPromise($value) { + // @phpstan-ignore-next-line return $this->returnCallback(is_callable($value) ? $value : function () use ($value) { yield $value; }); @@ -89,7 +90,7 @@ protected function setUpSchema($schema, $id = 'test', array $values = []): void $this->schemaPluginManager->method('createInstance') ->with($this->equalTo($id)) - ->will($this->returnValue($this->schema)); + ->willReturn($this->schema); $this->container->set('plugin.manager.graphql.schema', $this->schemaPluginManager); } @@ -169,14 +170,14 @@ protected function mockSchemaPluginManager($id): void { $this->schemaPluginManager->expects($this->any()) ->method('getDefinitions') - ->will($this->returnValue([ + ->willReturn([ $id => [ 'id' => $id, 'name' => 'Test schema', 'provider' => 'graphql', 'class' => '\Drupal\graphql\Plugin\GraphQL\Schema\SdlSchemaPluginBase', ], - ])); + ]); } /** From bed4f9757c180b1d1e9ab6d19d58344ab8a8be7b Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 26 Jul 2024 01:07:38 +0530 Subject: [PATCH 11/18] Adjusting phpstan warning for D11 only. --- .github/workflows/testing.yml | 3 --- src/GraphQL/Utility/FileUpload.php | 1 - src/Routing/QueryRouteEnhancer.php | 1 + .../DataProducer/Entity/Fields/Image/ImageDerivativeTest.php | 5 +++++ tests/src/Kernel/DataProducer/EntityReferenceTest.php | 3 +-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 452c23cf7..3c0d329ba 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -22,9 +22,6 @@ jobs: drupal-core: '10.2.x' phpstan: '0' # We only need to run PHPStan once on the latest PHP version. - - php-versions: '8.3' - drupal-core: '10.3.x' - phpstan: '1' - php-versions: '8.3' drupal-core: '11.0.x' phpstan: '1' diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 7d1aff08c..baad4374c 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -514,7 +514,6 @@ protected function prepareFilename(string $filename, array &$validators): string // If the file will be rejected anyway due to a disallowed extension, it // should not be renamed; rather, we'll let fileValidator service // to validate FileExtension reject it below. - $passes_validation = FALSE; if (!empty($validators['FileExtension']['extensions'])) { /** @var \Drupal\file\FileInterface $file */ diff --git a/src/Routing/QueryRouteEnhancer.php b/src/Routing/QueryRouteEnhancer.php index ae063b4f9..079f90e49 100644 --- a/src/Routing/QueryRouteEnhancer.php +++ b/src/Routing/QueryRouteEnhancer.php @@ -92,6 +92,7 @@ protected function assertValidPostRequestHeaders(Request $request) : void { return; } + // @phpstan-ignore-next-line $content_format = method_exists($request, 'getContentTypeFormat') ? $request->getContentTypeFormat() : $request->getContentType(); if ($content_format === NULL) { // Symfony before 5.4 does not detect "multipart/form-data", check for it diff --git a/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php b/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php index 375fff3ae..18ef12b7c 100644 --- a/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php +++ b/tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php @@ -62,6 +62,11 @@ public function setUp(): void { $this->file->method('getFileUri')->willReturn($this->fileUri); $this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag'])); + // @todo Remove hard-coded properties and only rely on image factory. + // @phpstan-ignore-next-line + @$this->file->width = 600; + // @phpstan-ignore-next-line + @$this->file->height = 400; $this->style = ImageStyle::create(['name' => 'test_style']); $effect = [ diff --git a/tests/src/Kernel/DataProducer/EntityReferenceTest.php b/tests/src/Kernel/DataProducer/EntityReferenceTest.php index 3b7700eff..976ce0e14 100644 --- a/tests/src/Kernel/DataProducer/EntityReferenceTest.php +++ b/tests/src/Kernel/DataProducer/EntityReferenceTest.php @@ -5,9 +5,8 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; -use Drupal\Tests\graphql\Kernel\GraphQLTestBase; use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; - +use Drupal\Tests\graphql\Kernel\GraphQLTestBase; /** * Tests the entity_reference data producers. From da60ac4f6ab942da15cb36fceacd9caeef736436 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Tue, 30 Jul 2024 13:55:36 +0530 Subject: [PATCH 12/18] PR feedback changes. --- src/GraphQL/Response/Response.php | 2 +- src/GraphQL/Response/ResponseInterface.php | 8 +++----- src/GraphQL/Utility/FileUpload.php | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/GraphQL/Response/Response.php b/src/GraphQL/Response/Response.php index 4467445bc..20b2c4eff 100644 --- a/src/GraphQL/Response/Response.php +++ b/src/GraphQL/Response/Response.php @@ -27,7 +27,7 @@ public function addViolation($message, array $properties = []): void { /** * {@inheritdoc} */ - public function addViolations($messages, array $properties = []): void { + public function addViolations(array $messages, array $properties = []): void { foreach ($messages as $message) { $this->addViolation($message, $properties); } diff --git a/src/GraphQL/Response/ResponseInterface.php b/src/GraphQL/Response/ResponseInterface.php index eba425edf..f8f050ab0 100644 --- a/src/GraphQL/Response/ResponseInterface.php +++ b/src/GraphQL/Response/ResponseInterface.php @@ -4,8 +4,6 @@ namespace Drupal\graphql\GraphQL\Response; -use Symfony\Component\Validator\ConstraintViolationListInterface; - /** * Response interface used for GraphQL responses. */ @@ -14,7 +12,7 @@ interface ResponseInterface { /** * Adds the violation. * - * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup|\Symfony\Component\Validator\ConstraintViolationListInterface $message + * @param string|\Drupal\Core\StringTranslation\TranslatableMarkup $message * Violation message. * @param array $properties * Other properties related to the violation. @@ -24,12 +22,12 @@ public function addViolation($message, array $properties = []): void; /** * Adds multiple violations. * - * @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[]|\Symfony\Component\Validator\ConstraintViolationListInterface $messages + * @param string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] $messages * Violation messages. * @param array $properties * Other properties related to the violation. */ - public function addViolations(array|ConstraintViolationListInterface $messages, array $properties = []): void; + public function addViolations(array $messages, array $properties = []): void; /** * Gets the violations. diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index baad4374c..2f1df2fa2 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -281,11 +281,13 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi $file->setSize(@filesize($temp_file_path)); // Validate against fileValidator first with the temporary path. - /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */ - $errors = $this->fileValidator->validate($file, $validators); - if (count($errors) > 0) { - $response->addViolations($errors); - return $response; + /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $file_validate_errors */ + $file_validate_errors = $this->fileValidator->validate($file, $validators); + $errors = []; + if (count($file_validate_errors) > 0) { + foreach ($file_validate_errors as $violation) { + $errors[] = $violation->getMessage(); + } } // Validate Image resolution. @@ -294,11 +296,14 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi if (!empty($maxResolution) || !empty($minResolution)) { $image_resolution_errors = $this->validateFileImageResolution($file, $maxResolution, $minResolution); if (!empty($image_resolution_errors)) { - $response->addViolations($image_resolution_errors); - return $response; + $errors = array_merge($errors, $image_resolution_errors); } } + if (!empty($errors)) { + $response->addViolations($errors); + return $response; + } $file->setFileUri($file_uri); // Move the file to the correct location after validation. Use // FileSystemInterface::EXISTS_ERROR as the file location has already been From 019cb04daa7f50e648f9ef125f4e73f06744930b Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 16:30:15 +0530 Subject: [PATCH 13/18] PR feedback changes. --- .github/workflows/testing.yml | 2 +- src/GraphQL/Utility/FileUpload.php | 7 ++----- tests/src/Kernel/Framework/UploadFileServiceTest.php | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3c0d329ba..b3f04e113 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['8.1', '8.2'] + php-versions: ['8.1', '8.2', '8.3'] drupal-core: ['10.3.x'] phpstan: ['0'] include: diff --git a/src/GraphQL/Utility/FileUpload.php b/src/GraphQL/Utility/FileUpload.php index 2f1df2fa2..2282ce831 100644 --- a/src/GraphQL/Utility/FileUpload.php +++ b/src/GraphQL/Utility/FileUpload.php @@ -37,7 +37,7 @@ class FileUpload { use StringTranslationTrait; /** - * The entity storage for the 'file' entity type. + * The file storage where we will create new file entities from. * * @var \Drupal\file\FileStorageInterface */ @@ -294,10 +294,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi $maxResolution = $settings['max_resolution'] ?? 0; $minResolution = $settings['min_resolution'] ?? 0; if (!empty($maxResolution) || !empty($minResolution)) { - $image_resolution_errors = $this->validateFileImageResolution($file, $maxResolution, $minResolution); - if (!empty($image_resolution_errors)) { - $errors = array_merge($errors, $image_resolution_errors); - } + $errors += $this->validateFileImageResolution($file, $maxResolution, $minResolution); } if (!empty($errors)) { diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index dffb9c3a2..c8db3a75f 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -15,6 +15,11 @@ */ class UploadFileServiceTest extends GraphQLTestBase { + /** + * {@inheritdoc} + */ + protected static $modules = ['file_validator_test']; + /** * The FileUpload object we want to test, gets prepared in setUp(). * From 6ca1db407458591039e3aa5c08ac6d443212d97e Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 16:46:59 +0530 Subject: [PATCH 14/18] Adding graphql_file_validate with subscriber. --- .../graphql_file_validate.info.yml | 5 +++ .../graphql_file_validate.module | 17 ++++++++++ .../graphql_file_validate.services.yml | 5 +++ .../GraphqlFileValidationTestSubscriber.php | 32 +++++++++++++++++++ .../Framework/UploadFileServiceTest.php | 2 +- 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.info.yml create mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.module create mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.services.yml create mode 100644 tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml new file mode 100644 index 000000000..0697cef6d --- /dev/null +++ b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml @@ -0,0 +1,5 @@ +type: module +name: GraphQL File Validate Test +description: Tests file validate on uploads. +package: Testing +hidden: TRUE \ No newline at end of file diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.module b/tests/modules/graphql_file_validate/graphql_file_validate.module new file mode 100644 index 000000000..e38dbc95a --- /dev/null +++ b/tests/modules/graphql_file_validate/graphql_file_validate.module @@ -0,0 +1,17 @@ +getFileUri())) { + throw new \Exception('File does not exist during validation: ' . $file->getFileUri()); + } +} diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.services.yml b/tests/modules/graphql_file_validate/graphql_file_validate.services.yml new file mode 100644 index 000000000..57167a17f --- /dev/null +++ b/tests/modules/graphql_file_validate/graphql_file_validate.services.yml @@ -0,0 +1,5 @@ +services: + graphql_file_validate_test_subscriber: + class: Drupal\graphql_file_validate\EventSubscriber\GraphqlFileValidationTestSubscriber + tags: + - { name: event_subscriber } diff --git a/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php new file mode 100644 index 000000000..723507610 --- /dev/null +++ b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php @@ -0,0 +1,32 @@ +file->id()]); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents(): array { + return [FileValidationEvent::class => 'onFileValidation']; + } + +} diff --git a/tests/src/Kernel/Framework/UploadFileServiceTest.php b/tests/src/Kernel/Framework/UploadFileServiceTest.php index c8db3a75f..c119895c2 100644 --- a/tests/src/Kernel/Framework/UploadFileServiceTest.php +++ b/tests/src/Kernel/Framework/UploadFileServiceTest.php @@ -18,7 +18,7 @@ class UploadFileServiceTest extends GraphQLTestBase { /** * {@inheritdoc} */ - protected static $modules = ['file_validator_test']; + protected static $modules = ['graphql_file_validate']; /** * The FileUpload object we want to test, gets prepared in setUp(). From cda2b778b5fdc296c9dc79573626f17ada834430 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 16:49:45 +0530 Subject: [PATCH 15/18] Adding comment. --- .github/workflows/testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b3f04e113..8ef1367c1 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -7,6 +7,7 @@ on: jobs: drupal: name: Drupal ${{ matrix.drupal-core }} (PHP ${{ matrix.php-versions }}) + # We cannot use ubuntu-latest right now as it still points to 22.04 and we need a newer database driver." runs-on: ubuntu-24.04 env: extensions: mbstring, xml, pdo_sqlite, gd, opcache From dd9a986e24db8dcd631d4f4d2474ae5ce6ea2504 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 16:55:21 +0530 Subject: [PATCH 16/18] Updating eventSubscriber to use fileInterface. --- .../graphql_file_validate/graphql_file_validate.info.yml | 2 +- .../modules/graphql_file_validate/graphql_file_validate.module | 2 +- .../src/EventSubscriber/GraphqlFileValidationTestSubscriber.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml index 0697cef6d..c548ca7c1 100644 --- a/tests/modules/graphql_file_validate/graphql_file_validate.info.yml +++ b/tests/modules/graphql_file_validate/graphql_file_validate.info.yml @@ -2,4 +2,4 @@ type: module name: GraphQL File Validate Test description: Tests file validate on uploads. package: Testing -hidden: TRUE \ No newline at end of file +hidden: TRUE diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.module b/tests/modules/graphql_file_validate/graphql_file_validate.module index e38dbc95a..027f3a360 100644 --- a/tests/modules/graphql_file_validate/graphql_file_validate.module +++ b/tests/modules/graphql_file_validate/graphql_file_validate.module @@ -10,7 +10,7 @@ use Drupal\file\FileInterface; /** * Test to validate file exists. */ -function graphql_file_validate(FileInterface $file): void { +function graphql_file_validate_test_file(FileInterface $file): void { if (!file_exists($file->getFileUri())) { throw new \Exception('File does not exist during validation: ' . $file->getFileUri()); } diff --git a/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php index 723507610..819373671 100644 --- a/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php +++ b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php @@ -19,7 +19,7 @@ class GraphqlFileValidationTestSubscriber implements EventSubscriberInterface { * The event. */ public function onFileValidation(FileValidationEvent $event): void { - graphql_file_validate('validate', [$event->file->id()]); + graphql_file_validate_test_file($event->file); } /** From 27327f6553806c343c7d4c8e7f15aa25b67cd7f0 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 17:26:25 +0530 Subject: [PATCH 17/18] Reverting changes for alterableSchemaTest. --- .../Entity/Fields/Image/ImageDerivative.php | 6 +++--- tests/src/Kernel/AlterableSchemaTest.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php index 0454a69cc..1df82d3a4 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php @@ -97,12 +97,12 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable $access = $entity->access('view', NULL, TRUE); $metadata->addCacheableDependency($access); if ($access->isAllowed() && $image_style = ImageStyle::load($style)) { - + // @phpstan-ignore-next-line $width = $entity->width; + // @phpstan-ignore-next-line $height = $entity->height; - // @phpstan-ignore-next-line - if (empty($width) || empty($height)) { + if ($width == NULL || $height == NULL) { /** @var \Drupal\Core\Image\ImageInterface $image */ $image = \Drupal::service('image.factory')->get($entity->getFileUri()); if ($image->isValid()) { diff --git a/tests/src/Kernel/AlterableSchemaTest.php b/tests/src/Kernel/AlterableSchemaTest.php index c77c4aaa5..961e46645 100644 --- a/tests/src/Kernel/AlterableSchemaTest.php +++ b/tests/src/Kernel/AlterableSchemaTest.php @@ -114,9 +114,9 @@ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded(): void $this->assertSame([ 'errors' => [ 0 => [ - 'message' => 'Cannot query field "empty" on type "Result".', + 'message' => 'Internal server error', 'extensions' => [ - 'category' => 'graphql', + 'category' => 'internal', ], 'locations' => [ 0 => [ @@ -124,8 +124,16 @@ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded(): void 'column' => 37, ], ], + 'path' => [ + 'alterableQuery', + // Reference to our variable in the error. + 'empty', + ], ], ], + 'data' => [ + 'alterableQuery' => NULL, + ], ], json_decode($result->getContent(), TRUE)); } @@ -146,6 +154,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void { $extensions['graphql_alterable_schema_test']->expects(static::any()) ->method('getBaseDefinition') ->willReturn(''); + // Different extension definition for different tests. // PHPUnit compatibility: remove once support for Drupal 10.2 is dropped. $methodName = method_exists($this, 'name') ? 'name' : 'getName'; From b08ea7d087eda363b47468a44dda297e85cb6f88 Mon Sep 17 00:00:00 2001 From: Ankit Pathak Date: Fri, 2 Aug 2024 17:45:00 +0530 Subject: [PATCH 18/18] Moving module changes into eventSubscriber. --- .github/workflows/testing.yml | 2 +- .../graphql_file_validate.module | 17 ----------------- .../GraphqlFileValidationTestSubscriber.php | 4 +++- 3 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 tests/modules/graphql_file_validate/graphql_file_validate.module diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8ef1367c1..89da49b3d 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -7,7 +7,7 @@ on: jobs: drupal: name: Drupal ${{ matrix.drupal-core }} (PHP ${{ matrix.php-versions }}) - # We cannot use ubuntu-latest right now as it still points to 22.04 and we need a newer database driver." + # We cannot use ubuntu-latest right now as it still points to 22.04 and we need a newer database driver. runs-on: ubuntu-24.04 env: extensions: mbstring, xml, pdo_sqlite, gd, opcache diff --git a/tests/modules/graphql_file_validate/graphql_file_validate.module b/tests/modules/graphql_file_validate/graphql_file_validate.module deleted file mode 100644 index 027f3a360..000000000 --- a/tests/modules/graphql_file_validate/graphql_file_validate.module +++ /dev/null @@ -1,17 +0,0 @@ -getFileUri())) { - throw new \Exception('File does not exist during validation: ' . $file->getFileUri()); - } -} diff --git a/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php index 819373671..ddfe155bb 100644 --- a/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php +++ b/tests/modules/graphql_file_validate/src/EventSubscriber/GraphqlFileValidationTestSubscriber.php @@ -19,7 +19,9 @@ class GraphqlFileValidationTestSubscriber implements EventSubscriberInterface { * The event. */ public function onFileValidation(FileValidationEvent $event): void { - graphql_file_validate_test_file($event->file); + if (!file_exists($event->file->getFileUri())) { + throw new \Exception('File does not exist during validation: ' . $event->file->getFileUri()); + } } /**