1 image_example.test public ImageExampleTestCase::testImageExample()

Test implementations of image API hooks.


modules/examples/image_example/tests/image_example.test, line 30
Test case for testing the image example module.


Functional tests for the Image Example module.


public function testImageExample() {
  // Login the admin user.

  // 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' => backdrop_strtolower($this->randomName()), 'label' => backdrop_strtolower($this->randomName()));
  $new_style = image_style_save($new_style);
  $this->assertTrue(isset($new_style['name']), format_string('Image style @style_name created.', array('@style_name' => $new_style['name'])));

  $edit = array(
    'new' => 'image_example_colorize',
  $this->backdropPost('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->backdropPost(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://DOCUMENTATION_PENDING is fixed.
  if (defined('bug_713872_fixed')) {
    $style = image_style_load($new_style['name']);
    config_set('image_example.settings', 'image_example_style_name', $style['name']);
    $style['name'] = backdrop_strtolower($this->randomName());
    $style = image_style_save($style);
    $variable = config_get('image_example.settings', 'image_example_style_name');
    $this->assertTrue(($variable == $style['name']), 'Variable image_example_style_name successfully updated when renaming image style.');