protected function RendererTestBase::randomContextValue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::randomContextValue()
Generates a random context value for the placeholder tests.
The #context array used by the placeholder #lazy_builder 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 #lazy_builder callback PlaceholdersTest::callback() renders 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 also
https://www.drupal.org/node/2151609
5 calls to RendererTestBase::randomContextValue()
- RendererPlaceholdersTest::generatePlaceholderElement in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererPlaceholdersTest.php - Generates an element with a placeholder.
- RendererPlaceholdersTest::providerPlaceholders in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererPlaceholdersTest.php - Provides the two classes of placeholders: cacheable and uncacheable.
- RendererPlaceholdersTest::testRecursivePlaceholder in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererPlaceholdersTest.php - Tests a placeholder that adds another placeholder.
- RendererTest::assertAccess in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererTest.php - Asserts that a render array with access checking renders correctly.
- RendererTest::providerTestRenderBasic in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererTest.php - Provides a list of render arrays to test basic rendering.
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ RendererTestBase.php, line 195 - Contains \Drupal\Tests\Core\Render\RendererTestBase.
Class
- RendererTestBase
- Base class for the actual unit tests testing \Drupal\Core\Render\Renderer.
Namespace
Drupal\Tests\Core\RenderCode
protected function randomContextValue() {
$tokens = [
'llama',
'alpaca',
'camel',
'moose',
'elk',
];
return $tokens[mt_rand(0, 4)];
}