Skip to content

Commit

Permalink
Bumping to D10.2 and fixing deprecation removed from D11.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jul 21, 2024
1 parent a2e4dcc commit c568a8d
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion graphql.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions graphql.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ services:
- '@renderer'
- '@event_dispatcher'
- '@image.factory'
- '@file.validator'

plugin.manager.graphql.persisted_query:
class: Drupal\graphql\Plugin\PersistedQueryPluginManager
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL/Response/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
24 changes: 15 additions & 9 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -111,6 +113,13 @@ class FileUpload {
*/
protected $imageFactory;

/**
* The file validator service.
*
* @var \Drupal\file\Validation\FileValidatorInterface
*/
protected FileValidatorInterface $fileValidator;

/**
* Constructor.
*/
Expand All @@ -126,6 +135,7 @@ public function __construct(
RendererInterface $renderer,
EventDispatcherInterface $eventDispatcher,
ImageFactory $image_factory,
FileValidatorInterface $file_validator,
) {
/** @var \Drupal\file\FileStorageInterface $file_storage */
$file_storage = $entityTypeManager->getStorage('file');
Expand All @@ -140,6 +150,7 @@ public function __construct(
$this->renderer = $renderer;
$this->eventDispatcher = $eventDispatcher;
$this->imageFactory = $image_factory;
$this->fileValidator = $file_validator;
}

/**
Expand Down Expand Up @@ -193,10 +204,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,
Expand Down Expand Up @@ -272,11 +280,9 @@ 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);
// Validate against fileValidator first with the temporary path.
/** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */
$errors = $this->fileValidator->validate($file, $validators);
$maxResolution = $settings['max_resolution'] ?? 0;
$minResolution = $settings['min_resolution'] ?? 0;
if (!empty($maxResolution) || !empty($minResolution)) {
Expand Down
1 change: 0 additions & 1 deletion tests/src/Kernel/AlterableSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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.
switch ($this->getName()) {
case 'testEmptySchemaExtensionAlteredQueryResultPropertyAdded':
Expand Down
11 changes: 6 additions & 5 deletions tests/src/Kernel/Framework/UploadFileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
Expand Down Expand Up @@ -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 <em class="placeholder">4 bytes</em> exceeding the maximum file size of <em class="placeholder">1 byte</em>.',
$violations[0]['message']
);
Expand Down Expand Up @@ -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 <em class="placeholder">15x15</em> pixels and the image size is <em class="placeholder">10</em>x<em class="placeholder">10</em> pixels.',
$violations[0]['message']
);
Expand Down Expand Up @@ -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: <em class="placeholder">odt</em>.',
$violations[0]['message']
);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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: <em class="placeholder">txt</em>.',
$violations[0]['message']
);
Expand Down
1 change: 1 addition & 0 deletions tests/src/Kernel/GraphQLTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ abstract class GraphQLTestBase extends KernelTestBase {
'content_translation',
'entity_reference_test',
'field',
'file',
'menu_link_content',
'link',
'typed_data',
Expand Down

0 comments on commit c568a8d

Please sign in to comment.