Commit 86acb042 authored by catch's avatar catch
Browse files

Issue #1402962 by msonnabaum, marcing, xjm: Fixed Render cache shouldn't treat...

Issue #1402962 by msonnabaum, marcing, xjm: Fixed Render cache shouldn't treat empty strings as a cache miss.
parent d2b8164d
...@@ -5766,9 +5766,12 @@ function drupal_render(&$elements) { ...@@ -5766,9 +5766,12 @@ function drupal_render(&$elements) {
} }
// Try to fetch the element's markup from cache and return. // Try to fetch the element's markup from cache and return.
if (isset($elements['#cache']) && $cached_output = drupal_render_cache_get($elements)) { if (isset($elements['#cache'])) {
$cached_output = drupal_render_cache_get($elements);
if ($cached_output !== FALSE) {
return $cached_output; return $cached_output;
} }
}
// If #markup is set, ensure #type is set. This allows to specify just #markup // If #markup is set, ensure #type is set. This allows to specify just #markup
// on an element without setting #type. // on an element without setting #type.
......
...@@ -1831,6 +1831,37 @@ class CommonDrupalRenderTestCase extends DrupalWebTestCase { ...@@ -1831,6 +1831,37 @@ class CommonDrupalRenderTestCase extends DrupalWebTestCase {
'@type' => var_export($element['#type'], TRUE), '@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;
}
} }
/** /**
......
Supports Markdown
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