diff --git a/core/modules/image/image.test b/core/modules/image/image.test index a29b4f3..2ab23ea 100644 --- a/core/modules/image/image.test +++ b/core/modules/image/image.test @@ -1128,4 +1128,53 @@ class ImageDimensionsUnitTest extends DrupalWebTestCase { $img_tag = theme_image_style($variables); $this->assertEqual($img_tag, '', t('Expected img tag was found.')); } + + /** + * Tests the image_scale_dimensions (and consequently + * image_dimensions_scale()) functions to return correct values. + */ + function testScaleDimensionsEffect() { + // Scale an image to be 320 pixels wide. + $data = array( + 'width' => 320, + 'height' => NULL, + 'upscale' => TRUE, + ); + + // Large landscape image scaled down. + $dimensions = array( + 'width' => 640, + 'height' => 480, + ); + image_scale_dimensions($dimensions, $data); + $this->assertEqual(320, $dimensions['width'], t('Width for the landscape dimensions have scaled down correctly.')); + $this->assertEqual(240, $dimensions['height'], t('Height for the landscape dimensions have scaled down correctly.')); + + // Large portrait image scaled down. + $dimensions = array( + 'width' => 640, + 'height' => 1280, + ); + image_scale_dimensions($dimensions, $data); + $this->assertEqual(320, $dimensions['width'], t('Width for the portrait dimensions have scaled down correctly.')); + $this->assertEqual(640, $dimensions['height'], t('Height for the portrait dimensions have scaled down correctly.')); + + // Small landscape image upscaled. + $dimensions = array( + 'width' => 160, + 'height' => 120, + ); + image_scale_dimensions($dimensions, $data); + $this->assertEqual(320, $dimensions['width'], t('Width for the landscape dimensions have scaled up correctly.')); + $this->assertEqual(240, $dimensions['height'], t('Height for the landscape dimensions have scaled up correctly.')); + + // Small portrait image upscaled. + $dimensions = array( + 'width' => 160, + 'height' => 320, + ); + image_scale_dimensions($dimensions, $data); + $this->assertEqual(320, $dimensions['width'], t('Width for the portrait dimensions have scaled up correctly.')); + $this->assertEqual(640, $dimensions['height'], t('Height for the portrait dimensions have scaled up correctly.')); + } }