// Maximum size.
if ($this->container->
get('image.factory'
)->
getToolkitId()) { // Copy the image so that the original doesn't get resized.
copy('core/misc/druplicon.png', 'temporary://druplicon.png'
);
$this->image->
setFileUri('temporary://druplicon.png'
);
$errors =
file_validate_image_resolution($this->image, '10x5'
);
$this->
assertCount(0,
$errors, 'No errors should be reported when an oversized image can be scaled down.'
);
$image =
$this->container->
get('image.factory'
)->
get($this->image->
getFileUri());
// Verify that the image was scaled to the correct width and height.
$this->
assertLessThanOrEqual(10,
$image->
getWidth());
$this->
assertLessThanOrEqual(5,
$image->
getHeight());
// Once again, now with negative width and height to force an error.
copy('core/misc/druplicon.png', 'temporary://druplicon.png'
);
$this->image->
setFileUri('temporary://druplicon.png'
);
$errors =
file_validate_image_resolution($this->image, '-10x-5'
);
$this->
assertCount(1,
$errors, 'An error reported for an oversized image that can not be scaled down.'
);
\Drupal::
service('file_system'
)->
unlink('temporary://druplicon.png'
);
} else {