function ImageExampleTestCase::testImageExample
Test implementations of image API hooks.
File
-
image_example/
image_example.test, line 42
Class
- ImageExampleTestCase
- Functional tests for the Image Example module.
Code
public function testImageExample() {
// Login the admin user.
$this->drupalLogin($this->webUser);
// Verify that the default style added by
// image_example_image_default_styles() is in the list of image styles.
$image_styles = image_styles();
$this->assertTrue(isset($image_styles['image_example_style']), 'The default style image_example_style is in the list of image styles.');
// Verify that the effect added to the default 'thumbnail' style by
// image_example_image_styles_alter() is present.
$this->assertTrue(isset($image_styles['thumbnail']['effects'][1]['name']) && $image_styles['thumbnail']['effects'][1]['name'] == 'image_example_colorize', 'Effect added to the thumbnail style via hook_image_styles_alter() is present.');
// Create a new image style and add the effect provided by
// image_example_effect_info().
$new_style = array(
'name' => drupal_strtolower($this->randomName()),
);
$new_style = image_style_save($new_style);
$this->assertTrue(isset($new_style['isid']), format_string('Image style @style_name created.', array(
'@style_name' => $new_style['name'],
)));
$edit = array(
'new' => 'image_example_colorize',
);
$this->drupalPost('admin/config/media/image-styles/edit/' . $new_style['name'], $edit, t('Add'));
// Verify the 'color' field provided by image_example_colorize_form()
// appears on the effect configuration page. And that we can fill it out.
$this->assertField('data[color]', 'Color field provided by image_example_effect_colorize_form is present on effect configuration page.');
$edit = array(
'data[color]' => '#000000',
);
$this->drupalPost(NULL, $edit, t('Add effect'));
$this->assertText(t('The image effect was successfully applied.'), format_string('Colorize effect added to @style_name.', array(
'@style_name' => $new_style['name'],
)));
// Set the variable 'image_example_style_name' to the name of our new style
// then rename the style and ensure the variable name is changed.
// @todo Enable this block once http://drupal.org/node/713872 is fixed.
if (defined('bug_713872_fixed')) {
$style = image_style_load($new_style['name']);
variable_set('image_example_style_name', $style['name']);
$style['name'] = drupal_strtolower($this->randomName());
$style = image_style_save($style);
$variable = variable_get('image_example_style_name', '');
$this->assertTrue($variable == $style['name'], 'Variable image_example_style_name successfully updated when renaming image style.');
}
}