From 86acb0421d01d325be2ccf4213b58ed3e498ec9e Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 19 Jan 2012 21:47:15 +0900 Subject: [PATCH] Issue #1402962 by msonnabaum, marcing, xjm: Fixed Render cache shouldn't treat empty strings as a cache miss. --- core/includes/common.inc | 7 +++-- core/modules/simpletest/tests/common.test | 31 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index b5ae3e39416..32f36b28a2c 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5766,8 +5766,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/core/modules/simpletest/tests/common.test b/core/modules/simpletest/tests/common.test index 5bad4efc983..d10f74ae913 100644 --- a/core/modules/simpletest/tests/common.test +++ b/core/modules/simpletest/tests/common.test @@ -1831,6 +1831,37 @@ class CommonDrupalRenderTestCase 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; + } } /**