Unverified Commit cbd00a5f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3522463 by klemendev, o'briat, kim.pepper:...

Issue #3522463 by klemendev, o'briat, kim.pepper: FileImageDimensionsConstraintValidator does not update file size (regression)

(cherry picked from commit 29704ed8)
parent 508258e3
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ public function validate(mixed $value, Constraint $constraint) {
        if ($image->scale($width, $height)) {
          $scaling = TRUE;
          $image->save();
          $file->setSize($image->getFileSize());
          if (!empty($width) && !empty($height)) {
            $this->messenger->addStatus($this->t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels. The new dimensions of the resized image are %new_widthx%new_height pixels.',
              [
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ protected function setUp(): void {
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $this->image->setFilename($file_system->basename($this->image->getFileUri()));
    $this->image->setSize(@filesize($this->image->getFileUri()));

    $this->nonImage = File::create();
    $this->nonImage->setFileUri('core/assets/scaffold/README.txt');
@@ -121,6 +122,8 @@ public function testFileValidateImageResolution(): void {
      // Verify that the image was scaled to the correct width and height.
      $this->assertLessThanOrEqual(10, $image->getWidth());
      $this->assertLessThanOrEqual(5, $image->getHeight());
      // Verify that the file size has been updated after resizing.
      $this->assertEquals($this->image->getSize(), $image->getFileSize());

      // Once again, now with negative width and height to force an error.
      copy('core/misc/druplicon.png', 'temporary://druplicon.png');