Issue #1402962 by msonnabaum, marcing, xjm: Fixed Render cache shouldn't treat empty strings as a cache miss.
parent
d2b8164d57
commit
86acb0421d
|
@ -5766,8 +5766,11 @@ 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'])) {
|
||||||
return $cached_output;
|
$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
|
// If #markup is set, ensure #type is set. This allows to specify just #markup
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue