1.20.x image.test | ImageEffectsUnitTest::testEffects() |
Test all the image effects provided by core.
File
- modules/
image/ tests/ image.test, line 298 - Tests for image.module.
Class
- ImageEffectsUnitTest
- Use the image_test.module's mock toolkit to ensure that the effects are properly passing parameters to the image toolkit.
Code
function testEffects() {
// Test the image_resize_effect() function.
$this->assertTrue(image_resize_effect($this->image, array('width' => 1, 'height' => 2)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical($calls['resize'][0][1], 1, 'Width was passed correctly');
$this->assertIdentical($calls['resize'][0][2], 2, 'Height was passed correctly');
image_test_reset();
// Test the image_scale_effect() function.
// @todo: need to test upscaling.
$this->assertTrue(image_scale_effect($this->image, array('width' => 10, 'height' => 10)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical($calls['resize'][0][1], 10, 'Width was passed correctly');
$this->assertIdentical($calls['resize'][0][2], 5, 'Height was based off aspect ratio and passed correctly');
image_test_reset();
// Test the image_crop_effect() function.
// @todo should test the keyword offsets.
$this->assertTrue(image_crop_effect($this->image, array('anchor' => 'top-1', 'width' => 3, 'height' => 4)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical($calls['crop'][0][1], 0, 'X was passed correctly');
$this->assertIdentical($calls['crop'][0][2], 1, 'Y was passed correctly');
$this->assertIdentical($calls['crop'][0][3], 3, 'Width was passed correctly');
$this->assertIdentical($calls['crop'][0][4], 4, 'Height was passed correctly');
image_test_reset();
// Test the image_scale_and_crop_effect() function.
$this->assertTrue(image_scale_and_crop_effect($this->image, array('width' => 5, 'height' => 10)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize', 'crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical($calls['crop'][0][1], 7.5, 'X was computed and passed correctly');
$this->assertIdentical($calls['crop'][0][2], 0.0, 'Y was computed and passed correctly');
$this->assertIdentical($calls['crop'][0][3], 5, 'Width was computed and passed correctly');
$this->assertIdentical($calls['crop'][0][4], 10, 'Height was computed and passed correctly');
image_test_reset();
// Test the image_desaturate_effect() function.
$this->assertTrue(image_desaturate_effect($this->image, array()), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('desaturate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical(count($calls['desaturate'][0]), 1, 'Only the image was passed.');
image_test_reset();
// Test the image_rotate_effect() function.
$this->assertTrue(image_rotate_effect($this->image, array('degrees' => 90, 'bgcolor' => '#fff')), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('rotate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertIdentical($calls['rotate'][0][1], 90, 'Degrees were passed correctly');
$this->assertIdentical($calls['rotate'][0][2], '#FFFFFF', 'Background color was passed correctly');
image_test_reset();
}