Skip to content
Snippets Groups Projects

Issue #3008292: ImageItem::getUploadValidators() should be the source of truth for validating uploaded images

Open Issue #3008292: ImageItem::getUploadValidators() should be the source of truth for validating uploaded images
Open Adam G-H requested to merge issue/drupal-3008292:3008292 into 11.x

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 177 $field_definition->setSetting('min_resolution', '32x32')->save();
    178 $validators = $item->getUploadValidators();
    179 $this->assertArrayHasKey('file_validate_is_image', $validators);
    180 $this->assertSame([0, '32x32'], $validators['file_validate_image_resolution']);
    181
    182 $field_definition->setSetting('min_resolution', NULL)
    183 ->setSetting('max_resolution', '1024x768')
    184 ->save();
    185 $validators = $item->getUploadValidators();
    186 $this->assertArrayHasKey('file_validate_is_image', $validators);
    187 $this->assertSame(['1024x768', 0], $validators['file_validate_image_resolution']);
    188
    189 $field_definition->setSetting('min_resolution', '32x32')->save();
    190 $validators = $item->getUploadValidators();
    191 $this->assertArrayHasKey('file_validate_is_image', $validators);
    192 $this->assertSame(['1024x768', '32x32'], $validators['file_validate_image_resolution']);
    • :clap:

      We already have explicit tests at \Drupal\Tests\rest\Functional\FileUploadResourceTestBase::testFileUploadLargerFileSize() and \Drupal\Tests\jsonapi\Functional\FileUploadTest::testFileUploadLargerFileSize() for REST and JSON:API respectively — we should to add sibling test methods to ensure image upload validators run! :fingers_crossed:

      And this would be a great starting point for those! :nerd:

    • @wimleers It may be tricky to add sibling test methods for images, because everything in the setUp() method sets up a regular file field and textual data to test with. Any thoughts on how I should cleanly approach this? One option we have is to change the REST and JSON:API tests to use an image field and image data, since image fields already do everything file fields do, and more. (That's essentially what I did to fix FileItemValidationTest.) What do you think?

      Edited by Adam G-H
    • changed this line in version 27 of the diff

    • Please register or sign in to reply
  • Adam G-H added 1 commit

    added 1 commit

    • 90cab856 - Add dedicated test of the media library resizing.

    Compare with previous version

  • Adam G-H added 1 commit

    added 1 commit

    • 231aa3f1 - Remove unnecessary comments in REST and JSON:API, and try to improve...

    Compare with previous version

  • Adam G-H added 1 commit

    added 1 commit

    • 8af8bfb0 - Make getUploadValidators() filter the allowed file extensions by the current...

    Compare with previous version

  • Adam G-H changed the description

    changed the description

  • Adam G-H changed target branch from 9.2.x to 9.3.x

    changed target branch from 9.2.x to 9.3.x

  • Adam G-H changed target branch from 9.3.x to 9.2.x

    changed target branch from 9.3.x to 9.2.x

  • Adam G-H added 359 commits

    added 359 commits

    Compare with previous version

  • Adam G-H changed target branch from 9.2.x to 9.3.x

    changed target branch from 9.2.x to 9.3.x

  • Max Pogonowski added 441 commits

    added 441 commits

    Compare with previous version

  • Yogesh Pawar added 249 commits

    added 249 commits

    Compare with previous version

  • Adam G-H changed target branch from 9.3.x to 10.1.x

    changed target branch from 9.3.x to 10.1.x

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading