Issue #1761086 by cam8001, Berdir, larowlan: Fixed Caching in image_effects_definitio...
authorDavid Rothstein
Sat, 15 Sep 2012 21:24:47 +0000 (17:24 -0400)
committerDavid Rothstein
Sat, 15 Sep 2012 21:24:47 +0000 (17:24 -0400)
modules/image/image.module
modules/image/image.test
modules/image/tests/image_module_test.module
modules/simpletest/tests/image.test

index fe3cfcd..5946e61 100644 (file)
@@ -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 {
index 75e9607..6a5d20f 100644 (file)
@@ -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.');
+  }
 }
 
 /**
index 0d398ab..8a322fb 100644 (file)
@@ -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++;
+}
index 962aa66..403c9d7 100644 (file)
@@ -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';