function RendererTestBase::setUp
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::setUp()
- 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::setUp()
- 10 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\RendererTestBase::setUp()
Overrides UnitTestCase::setUp
4 calls to RendererTestBase::setUp()
- RendererBubblingTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererBubblingTest.php - RendererCallbackTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererCallbackTest.php - RendererDebugTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererDebugTest.php - RendererPlaceholdersTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererPlaceholdersTest.php
4 methods override RendererTestBase::setUp()
- RendererBubblingTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererBubblingTest.php - RendererCallbackTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererCallbackTest.php - RendererDebugTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererDebugTest.php - RendererPlaceholdersTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ RendererPlaceholdersTest.php
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ RendererTestBase.php, line 126
Class
- RendererTestBase
- Base class for the actual unit tests testing \Drupal\Core\Render\Renderer.
Namespace
Drupal\Tests\Core\RenderCode
protected function setUp() : void {
parent::setUp();
$this->callableResolver = $this->createMock(CallableResolver::class);
$this->callableResolver
->expects($this->any())
->method('getCallableFromDefinition')
->willReturnArgument(0);
$this->themeManager = $this->createMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
$this->elementInfo = $this->createMock('Drupal\\Core\\Render\\ElementInfoManagerInterface');
$this->elementInfo
->expects($this->any())
->method('getInfo')
->willReturnCallback(function ($type) {
switch ($type) {
case 'details':
$info = [
'#theme_wrappers' => [
'details',
],
];
break;
case 'link':
$info = [
'#theme' => 'link',
];
break;
default:
$info = [];
}
$info['#defaults_loaded'] = TRUE;
return $info;
});
$this->requestStack = new RequestStack();
$request = new Request();
$request->server
->set('REQUEST_TIME', $_SERVER['REQUEST_TIME']);
$this->requestStack
->push($request);
$this->cacheFactory = $this->createMock('Drupal\\Core\\Cache\\VariationCacheFactoryInterface');
$this->cacheContextsManager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$this->cacheContextsManager
->method('assertValidTokens')
->willReturn(TRUE);
$this->cacheContextsManager
->expects($this->any())
->method('optimizeTokens')
->willReturnCallback(function ($context_tokens) {
return $context_tokens;
});
$current_user_role =& $this->currentUserRole;
$this->cacheContextsManager
->expects($this->any())
->method('convertTokensToKeys')
->willReturnCallback(function ($context_tokens) use (&$current_user_role) {
$keys = [];
foreach ($context_tokens as $context_id) {
switch ($context_id) {
case 'user.roles':
$keys[] = 'r.' . $current_user_role;
break;
case 'languages:language_interface':
$keys[] = 'en';
break;
case 'theme':
$keys[] = 'stark';
break;
default:
$keys[] = $context_id;
}
}
return new ContextCacheKeys($keys);
});
$this->placeholderGenerator = new PlaceholderGenerator($this->cacheContextsManager, $this->rendererConfig);
$this->renderCache = new PlaceholderingRenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager, $this->placeholderGenerator);
$this->renderer = new Renderer($this->callableResolver, $this->themeManager, $this->elementInfo, $this->placeholderGenerator, $this->renderCache, $this->requestStack, $this->rendererConfig);
$this->datetimeTime = new Time($this->requestStack);
$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $this->cacheContextsManager);
$container->set('render_cache', $this->renderCache);
$container->set('renderer', $this->renderer);
$container->set('datetime.time', $this->datetimeTime);
\Drupal::setContainer($container);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.