diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-01-21 11:00:42 -0800 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-01-21 11:00:42 -0800 |
commit | 6972dd4615f7e353f757dd04c4a55673cfad29d0 (patch) | |
tree | 25340fc5724083fa572e756727d423434897093f | |
parent | 8164434505e4292e5d584eebbf7b05b403d9c07b (diff) | |
download | brdo-6972dd4615f7e353f757dd04c4a55673cfad29d0.tar.gz brdo-6972dd4615f7e353f757dd04c4a55673cfad29d0.tar.bz2 |
Issue #1402962 by xjm, marcingy, oriol_e9g, msonnabaum: Fixed Render cache shouldn't treat empty strings as a cache miss.
-rw-r--r-- | includes/common.inc | 7 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 31 |
2 files changed, 36 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc index f8e40a961..3e79239f5 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -5679,8 +5679,11 @@ function drupal_render(&$elements) { } // Try to fetch the element's markup from cache and return. - if (isset($elements['#cache']) && $cached_output = drupal_render_cache_get($elements)) { - return $cached_output; + if (isset($elements['#cache'])) { + $cached_output = drupal_render_cache_get($elements); + if ($cached_output !== FALSE) { + return $cached_output; + } } // If #markup is set, ensure #type is set. This allows to specify just #markup diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 4a0240002..7e79450ff 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1747,6 +1747,37 @@ class DrupalRenderTestCase extends DrupalWebTestCase { '@type' => var_export($element['#type'], TRUE), ))); } + + /** + * Tests caching of an empty render item. + */ + function testDrupalRenderCache() { + // Force a request via GET. + $request_method = $_SERVER['REQUEST_METHOD']; + $_SERVER['REQUEST_METHOD'] = 'GET'; + // Create an empty element. + $test_element = array( + '#cache' => array( + 'cid' => 'render_cache_test', + ), + '#markup' => '', + ); + + // Render the element and confirm that it goes through the rendering + // process (which will set $element['#printed']). + $element = $test_element; + drupal_render($element); + $this->assertTrue(isset($element['#printed']), t('No cache hit')); + + // Render the element again and confirm that it is retrieved from the cache + // instead (so $element['#printed'] will not be set). + $element = $test_element; + drupal_render($element); + $this->assertFalse(isset($element['#printed']), t('Cache hit')); + + // Restore the previous request method. + $_SERVER['REQUEST_METHOD'] = $request_method; + } } /** |