function SmartcropTestCase::testCrop in Smart Crop 7
Same name and namespace in other branches
- 6 tests/smartcrop.test \SmartcropTestCase::testCrop()
File
- tests/
smartcrop.test, line 131 - Tests for the smartcrop module.
Class
- SmartcropTestCase
- @file Tests for the smartcrop module.
Code
function testCrop() {
// Create a preset with entropy crop.
$this
->drupalPost('admin/config/media/image-styles/add', array(
'name' => 'test2',
), t('Create new style'));
$this
->drupalPost(NULL, array(
'new' => 'smartcrop_crop',
), t('Add'));
$edit = array(
'data[width]' => '10',
'data[height]' => '10',
);
$this
->drupalPost(NULL, $edit, t('Add effect'));
// Create an image field that uses the new style.
$instance = $this
->createImageField('smartcrop_image', 'page');
$instance['display']['default']['type'] = 'image';
$instance['display']['default']['settings']['image_style'] = 'test2';
field_update_instance($instance);
$file = 'quarter.png';
$edit = array(
'title' => $this
->randomName(),
'files[smartcrop_image_und_0]' => realpath(dirname(__FILE__) . '/' . $file),
);
$this
->drupalPost('node/add/page', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title']);
$image_uri = $node->smartcrop_image[LANGUAGE_NONE][0]['uri'];
$this
->drupalGet(image_style_url('test2', $image_uri));
$this
->assertResponse(200, t('Retrieved cropped image.'));
$expected_image = imagecreatefrompng(dirname(__FILE__) . '/center.png');
$actual_image = imagecreatefrompng(image_style_url('test2', $image_uri));
$this
->assertImageEqual($actual_image, $expected_image, 1, t('@file was cropped correctly.', array(
'@file' => $file,
)));
// Clean up.
imagedestroy($expected_image);
imagedestroy($actual_image);
}