Commit a59d92e0 authored by Dries's avatar Dries
Browse files

Issue #1761086 by cam8001, Berdir: Fixed Caching in image_effects_definitions() broken.

parent 7e504e93
......@@ -978,7 +978,7 @@ function image_effect_definitions() {
$effects = &drupal_static(__FUNCTION__);
if (!isset($effects)) {
if ($cache = cache()->get("image_effects:$langcode") && !empty($cache->data)) {
if ($cache = cache()->get("image_effects:$langcode")) {
$effects = $cache->data;
}
else {
......
......@@ -20,7 +20,7 @@ class ImageEffectsTest extends ToolkitTestBase {
*
* @var array
*/
public static $modules = array('image_test');
public static $modules = array('image_test', 'image_module_test');
public static function getInfo() {
return array(
......@@ -119,4 +119,23 @@ function testRotateEffect() {
$this->assertEqual($calls['rotate'][0][1], 90, t('Degrees were passed correctly'));
$this->assertEqual($calls['rotate'][0][2], 0xffffff, t('Background color was passed correctly'));
}
/**
* Test image effect caching.
*/
function testImageEffectsCaching() {
$image_effect_definitions_called = &drupal_static('image_module_test_image_effect_info_alter');
// First call should grab a fresh copy of the data.
$effects = image_effect_definitions();
$this->assertTrue($image_effect_definitions_called === 1, 'image_effect_definitions() generated data.');
// Second call should come from cache.
drupal_static_reset('image_effect_definitions');
drupal_static_reset('image_module_test_image_effect_info_alter');
$cached_effects = image_effect_definitions();
$this->assertTrue(is_null($image_effect_definitions_called), 'image_effect_definitions() returned data from cache.');
$this->assertTrue($effects == $cached_effects, 'Cached effects are the same as generated effects.');
}
}
......@@ -38,3 +38,13 @@ function image_module_test_image_effect_info() {
function image_module_test_null_effect(array &$image, array $data) {
return TRUE;
}
/**
* Implements hook_image_effect_info_alter().
*
* Used to keep a count of cache misses in image_effect_definitions().
*/
function image_module_test_image_effect_info_alter(&$effects) {
$image_effects_definition_called = &drupal_static(__FUNCTION__, 0);
$image_effects_definition_called++;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment