function TitleResolverTest::testTitleClosure
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testTitleClosure()
Tests a title closure declared on the route attribute.
See also
\Drupal\Core\Controller\TitleResolver::getTitle()
File
-
core/
tests/ Drupal/ Tests/ Core/ Controller/ TitleResolverTest.php, line 289
Class
Namespace
Drupal\Tests\Core\ControllerCode
public function testTitleClosure() : void {
$request = new Request();
$route = new Route('/test-route', [
'_title' => 'static title',
'_title_closure' => [
TitleClosureCallback::class,
'example',
0,
],
]);
// The closure defined in the Route attribute is resolved and called with
// the arguments provided by the argument resolver.
$argumentResolver = $this->createMock(ArgumentResolverInterface::class);
$argumentResolver->expects($this->once())
->method('getArguments')
->with($request, $this->isInstanceOf(\Closure::class))
->willReturn([
'value',
]);
$this->titleResolver = new TitleResolver($this->controllerResolver, $this->translationManager, $argumentResolver);
$this->assertEquals(new TranslatableMarkup('Title for @value', [
'@value' => 'value',
]), $this->titleResolver
->getTitle($request, $route));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.