'Image toolkit tests', 'description' => 'Check image toolkit functions.', 'group' => 'Image', ); } /** * Check that hook_image_toolkits() is called and only available toolkits are * returned. */ function testGetAvailableToolkits() { $toolkits = image_get_available_toolkits(); $this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.'); $this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned'); $this->assertToolkitOperationsCalled(array()); } /** * Test the image_load() function. */ function testLoad() { $image = image_load($this->file, $this->toolkit); $this->assertTrue(is_object($image), 'Returned an object.'); $this->assertEqual($this->toolkit, $image->toolkit, 'Image had toolkit set.'); $this->assertToolkitOperationsCalled(array('load', 'get_info')); } /** * Test the image_save() function. */ function testSave() { $this->assertFalse(image_save($this->image), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('save')); } /** * Test the image_resize() function. */ function testResize() { $this->assertTrue(image_resize($this->image, 1, 2), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('resize')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual($calls['resize'][0][1], 1, 'Width was passed correctly'); $this->assertEqual($calls['resize'][0][2], 2, 'Height was passed correctly'); } /** * Test the image_scale() function. */ function testScale() { // TODO: need to test upscaling $this->assertTrue(image_scale($this->image, 10, 10), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('resize')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual($calls['resize'][0][1], 10, 'Width was passed correctly'); $this->assertEqual($calls['resize'][0][2], 5, 'Height was based off aspect ratio and passed correctly'); } /** * Test the image_scale_and_crop() function. */ function testScaleAndCrop() { $this->assertTrue(image_scale_and_crop($this->image, 5, 10), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('resize', 'crop')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual($calls['crop'][0][1], 7.5, 'X was computed and passed correctly'); $this->assertEqual($calls['crop'][0][2], 0, 'Y was computed and passed correctly'); $this->assertEqual($calls['crop'][0][3], 5, 'Width was computed and passed correctly'); $this->assertEqual($calls['crop'][0][4], 10, 'Height was computed and passed correctly'); } /** * Test the image_rotate() function. */ function testRotate() { $this->assertTrue(image_rotate($this->image, 90, 1), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('rotate')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual($calls['rotate'][0][1], 90, 'Degrees were passed correctly'); $this->assertEqual($calls['rotate'][0][2], 1, 'Background color was passed correctly'); } /** * Test the image_crop() function. */ function testCrop() { $this->assertTrue(image_crop($this->image, 1, 2, 3, 4), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('crop')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual($calls['crop'][0][1], 1, 'X was passed correctly'); $this->assertEqual($calls['crop'][0][2], 2, 'Y was passed correctly'); $this->assertEqual($calls['crop'][0][3], 3, 'Width was passed correctly'); $this->assertEqual($calls['crop'][0][4], 4, 'Height was passed correctly'); } /** * Test the image_desaturate() function. */ function testDesaturate() { $this->assertTrue(image_desaturate($this->image), 'Function returned the expected value.'); $this->assertToolkitOperationsCalled(array('desaturate')); // Check the parameters. $calls = image_test_get_all_calls(); $this->assertEqual(count($calls['desaturate'][0]), 1, 'Only the image was passed.'); } }