// Minimum size.
$errors =
file_validate_image_resolution($this->image
);
$this->
assertCount(0,
$errors, 'No errors for an image when there is no minimum or maximum resolution.'
);
$errors =
file_validate_image_resolution($this->image, 0, '200x1'
);
$this->
assertCount(1,
$errors, 'Got an error for an image that was not wide enough.'
);
$errors =
file_validate_image_resolution($this->image, 0, '1x200'
);
$this->
assertCount(1,
$errors, 'Got an error for an image that was not tall enough.'
);
$errors =
file_validate_image_resolution($this->image, 0, '200x200'
);
$this->
assertCount(1,
$errors, 'Small images report an error.'
);
// 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());