Commit 3b6b9774 authored by catch's avatar catch

Issue #2197359 by xjm, alexpott: Random failure in Drupal\system\Tests\Common\RenderTest.

parent a16b5639
......@@ -453,7 +453,7 @@ function testDrupalRenderCache() {
* Tests post-render cache callbacks functionality.
*/
function testDrupalRenderPostRenderCache() {
$context = array('foo' => $this->randomString());
$context = array('foo' => $this->randomContextValue());
$test_element = array();
$test_element['#markup'] = '';
$test_element['#attached']['js'][] = array('type' => 'setting', 'data' => array('foo' => 'bar'));
......@@ -553,9 +553,9 @@ function testDrupalRenderChildrenPostRenderCache() {
// Create an element with a child and subchild. Each element has the same
// #post_render_cache callback, but with different contexts.
drupal_static_reset('_drupal_add_js');
$context_1 = array('foo' => $this->randomString());
$context_2 = array('bar' => $this->randomString());
$context_3 = array('baz' => $this->randomString());
$context_1 = array('foo' => $this->randomContextValue());
$context_2 = array('bar' => $this->randomContextValue());
$context_3 = array('baz' => $this->randomContextValue());
$test_element = array(
'#type' => 'details',
'#cache' => array(
......@@ -770,7 +770,7 @@ function testDrupalRenderChildrenPostRenderCache() {
* Tests post-render cache-integrated 'render_cache_placeholder' element.
*/
function testDrupalRenderRenderCachePlaceholder() {
$context = array('bar' => $this->randomString());
$context = array('bar' => $this->randomContextValue());
$test_element = array(
'#type' => 'render_cache_placeholder',
'#context' => $context,
......@@ -846,4 +846,25 @@ protected function parseDrupalSettings($html) {
return $parsed_settings;
}
/**
* Generates a random context value for the post-render cache tests.
*
* The #context array used by the post-render cache callback will generally
* be used to provide metadata like entity IDs, field machine names, paths,
* etc. for JavaScript replacement of content or assets. In this test, the
* callbacks common_test_post_render_cache() and
* common_test_post_render_cache_placeholder() render the context inside test
* HTML, so using any random string would sometimes cause random test
* failures because the test output would be unparseable. Instead, we provide
* random tokens for replacement.
*
* @see common_test_post_render_cache()
* @see common_test_post_render_cache_placeholder()
* @see https://drupal.org/node/2151609
*/
protected function randomContextValue() {
$tokens = array('llama', 'alpaca', 'camel', 'moose', 'elk');
return $tokens[mt_rand(0, 4)];
}
}
Markdown is supported
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