summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rothstein2012-09-15 21:24:47 (GMT)
committer David Rothstein2012-09-15 21:24:47 (GMT)
commit4d392996a29b5e650018d403684333884530b9c6 (patch)
treebcaceb7598a2437898f991fe66ca140ff0614bec
parenta6cc373efafadca346d94d1e8ccb9f31b9c5f4a0 (diff)
Issue #1761086 by cam8001, Berdir, larowlan: Fixed Caching in image_effects_definitions() broken.
-rw-r--r--modules/image/image.module2
-rw-r--r--modules/image/image.test21
-rw-r--r--modules/image/tests/image_module_test.module10
-rw-r--r--modules/simpletest/tests/image.test8
4 files changed, 38 insertions, 3 deletions
diff --git a/modules/image/image.module b/modules/image/image.module
index fe3cfcd..5946e61 100644
--- a/modules/image/image.module
+++ b/modules/image/image.module
@@ -1054,7 +1054,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 {
diff --git a/modules/image/image.test b/modules/image/image.test
index 75e9607..6a5d20f 100644
--- a/modules/image/image.test
+++ b/modules/image/image.test
@@ -255,7 +255,7 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
}
function setUp() {
- parent::setUp('image_test');
+ parent::setUp('image_module_test');
module_load_include('inc', 'image', 'image.effects');
}
@@ -342,6 +342,25 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
$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.');
+ }
}
/**
diff --git a/modules/image/tests/image_module_test.module b/modules/image/tests/image_module_test.module
index 0d398ab..8a322fb 100644
--- a/modules/image/tests/image_module_test.module
+++ b/modules/image/tests/image_module_test.module
@@ -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++;
+}
diff --git a/modules/simpletest/tests/image.test b/modules/simpletest/tests/image.test
index 962aa66..403c9d7 100644
--- a/modules/simpletest/tests/image.test
+++ b/modules/simpletest/tests/image.test
@@ -14,7 +14,13 @@ class ImageToolkitTestCase extends DrupalWebTestCase {
protected $image;
function setUp() {
- parent::setUp('image_test');
+ $modules = func_get_args();
+ if (isset($modules[0]) && is_array($modules[0])) {
+ $modules = $modules[0];
+ }
+ $modules[] = 'image_test';
+
+ parent::setUp($modules);
// Use the image_test.module's test toolkit.
$this->toolkit = 'test';