Commit 90547993 authored by Drew Webber's avatar Drew Webber
Browse files

Issue #1973278 by mcdruid, drasgardian, alesr, AaronBauman: Error in...

Issue #1973278 by mcdruid, drasgardian, alesr, AaronBauman: Error in image_styles when an effect has no definition
parent 3a4c2c2e
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -583,9 +583,19 @@ function image_styles() {
          $style['storage'] = IMAGE_STORAGE_DEFAULT;
          foreach ($style['effects'] as $key => $effect) {
            $definition = image_effect_definition_load($effect['name']);
            if ($definition) {
              $effect = array_merge($definition, $effect);
              $style['effects'][$key] = $effect;
            }
            else {
              watchdog('image', 'Image style %style_name has an effect %effect_name with no definition.',
                array(
                  '%style_name' => $style_name,
                  '%effect_name' => $effect['name'],
                  ),
                WATCHDOG_ERROR);
            }
          }
          $styles[$style_name] = $style;
        }
      }
+22 −1
Original line number Diff line number Diff line
@@ -31,7 +31,12 @@ class ImageFieldTestCase extends DrupalWebTestCase {
  protected $admin_user;

  function setUp() {
    parent::setUp('image');
    $modules = func_get_args();
    if (isset($modules[0]) && is_array($modules[0])) {
      $modules = $modules[0];
    }
    $modules[] = 'image';
    parent::setUp($modules);
    $this->admin_user = $this->drupalCreateUser(array('access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer nodes', 'create article content', 'edit any article content', 'delete any article content', 'administer image styles', 'administer fields'));
    $this->drupalLogin($this->admin_user);
  }
@@ -573,6 +578,10 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
    );
  }

  function setUp() {
    parent::setUp('image_module_test', 'image_module_styles_test');
  }

  /**
   * Given an image style, generate an image.
   */
@@ -893,6 +902,18 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
    $this->drupalGet('node/' . $nid);
    $this->assertRaw(check_plain(image_style_url('thumbnail', $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), format_string('Image displayed using style replacement style.'));
  }

  /**
   * Test disabling a module providing an effect in use by an image style.
   */
  function testOrphanedEffect() {
    // This will not check whether anything depends on the module.
    module_disable(array('image_module_test'), FALSE);
    $this->drupalGet('admin/config/media/image-styles');
    $this->assertText('Test Image Style', 'Image style with an orphaned effect displayed in the list of styles.');
    $image_log = db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC', 0, 1, array(':type' => 'image'))->fetchField();
    $this->assertEqual('Image style %style_name has an effect %effect_name with no definition.', $image_log, 'A watchdog message was logged for the broken image style effect');
  }
}

/**
+8 −0
Original line number Diff line number Diff line
name = Image Styles test
description = Provides additional hook implementations for testing Image Styles functionality.
package = Core
version = VERSION
core = 7.x
files[] = image_module_styles_test.module
dependencies[] = image_module_test
hidden = TRUE
+29 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Provides additional Image module hook implementations for testing purposes.
 */

/**
 * Implements hook_image_default_styles().
 */
function image_module_styles_test_image_default_styles() {
  $styles = array();

  $styles['test_image_style'] = array(
    'label' => 'Test Image Style',
    'effects' => array(
      array(
        'name' => 'image_scale',
        'data' => array('width' => 100, 'height' => 100, 'upscale' => 1),
        'weight' => 0,
      ),
      array(
        'name' => 'image_module_test_null',
      ),
    )
  );

  return $styles;
}
+3 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ function image_module_test_file_download($uri) {
function image_module_test_image_effect_info() {
  $effects = array(
    'image_module_test_null' => array(
      'label' => 'image_module_test_null',
      'effect callback' => 'image_module_test_null_effect',
    ),
  );
@@ -38,7 +39,7 @@ function image_module_test_image_effect_info() {
 * @return
 *   TRUE
 */
function image_module_test_null_effect(array &$image, array $data) {
function image_module_test_null_effect(&$image, array $data) {
  return TRUE;
}