core/modules/image/image.test | 130 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) diff --git a/core/modules/image/image.test b/core/modules/image/image.test index a29b4f3..48a7a9a 100644 --- a/core/modules/image/image.test +++ b/core/modules/image/image.test @@ -1129,3 +1129,133 @@ class ImageDimensionsUnitTest extends DrupalWebTestCase { $this->assertEqual($img_tag, '', t('Expected img tag was found.')); } } + +/** + * Tests image_dimensions_scale(). + */ +class ImageDimensionsScaleTestCase extends DrupalUnitTestCase { + public static function getInfo() { + return array( + 'name' => 'image_dimensions_scale()', + 'description' => 'Tests all control flow branches in image_dimensions_scale().', + 'group' => 'Image', + ); + } + + /** + * Tests all control flow branches in image_dimensions_scale(). + */ + function testImageDimensionsScale() { + + // no height + // upscale, don't need to upscale + $tests[] = array( + 'input' => array( + 'dimensions' => array( + 'width' => 1000, + 'height' => 2000, + ), + 'width' => 200, + 'height' => NULL, + 'upscale' => TRUE, + ), + 'output' => array( + 'dimensions' => array( + 'width' => 200, + 'height' => 400, + ), + 'return_value' => TRUE, + ), + ); + + // no width + // don't upscale, don't need to upscale + $tests[] = array( + 'input' => array( + 'dimensions' => array( + 'width' => 1000, + 'height' => 800, + ), + 'width' => NULL, + 'height' => 140, + 'upscale' => FALSE, + ), + 'output' => array( + 'dimensions' => array( + 'width' => 175, + 'height' => 140, + ), + 'return_value' => TRUE, + ), + ); + + // source aspect ratio greater than target + // upscale, need to upscale + $tests[] = array( + 'input' => array( + 'dimensions' => array( + 'width' => 8, + 'height' => 20, + ), + 'width' => 200, + 'height' => 140, + 'upscale' => TRUE, + ), + 'output' => array( + 'dimensions' => array( + 'width' => 56, + 'height' => 140, + ), + 'return_value' => TRUE, + ), + ); + + // target aspect ratio greater than source + $tests[] = array( + 'input' => array( + 'dimensions' => array( + 'width' => 2000, + 'height' => 800, + ), + 'width' => 200, + 'height' => 140, + 'upscale' => FALSE, + ), + 'output' => array( + 'dimensions' => array( + 'width' => 200, + 'height' => 80, + ), + 'return_value' => TRUE, + ), + ); + + // don't upscale, need to upscale + $tests[] = array( + 'input' => array( + 'dimensions' => array( + 'width' => 100, + 'height' => 50, + ), + 'width' => 200, + 'height' => 140, + 'upscale' => FALSE, + ), + 'output' => array( + 'dimensions' => array( + 'width' => 100, + 'height' => 50, + ), + 'return_value' => FALSE, + ), + ); + + foreach ($tests as $test) { + $return_value = image_dimensions_scale($test['input']['dimensions'], $test['input']['width'], $test['input']['height'], $test['input']['upscale']); + + $this->assertEqual($test['output']['dimensions']['width'], $test['input']['dimensions']['width'], t('Correct width.')); + $this->assertEqual($test['output']['dimensions']['height'], $test['input']['dimensions']['height'], t('Correct height.')); + $this->assertEqual($test['output']['return_value'], $return_value, t('Correct return value.')); + } + } +}