function TitleResolverTest::testDynamicTitle

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testDynamicTitle()
  2. 10 core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testDynamicTitle()
  3. 9 core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testDynamicTitle()
  4. 8.9.x core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php \Drupal\Tests\Core\Controller\TitleResolverTest::testDynamicTitle()

Tests a dynamic title.

Attributes

#[DataProvider('providerTestDynamicTitle')]

See also

\Drupal\Core\Controller\TitleResolver::getTitle()

File

core/tests/Drupal/Tests/Core/Controller/TitleResolverTest.php, line 244

Class

TitleResolverTest
Tests Drupal\Core\Controller\TitleResolver.

Namespace

Drupal\Tests\Core\Controller

Code

public function testDynamicTitle(\Stringable|string|array|null $title, \Stringable|string|array|null $expected) : void {
  $request = new Request();
  $route = new Route('/test-route', [
    '_title' => 'static title',
    '_title_callback' => 'Drupal\\Tests\\Core\\Controller\\TitleCallback::example',
  ]);
  $callable = [
    new TitleCallback(),
    'example',
  ];
  $this->controllerResolver
    ->expects($this->once())
    ->method('getControllerFromDefinition')
    ->with('Drupal\\Tests\\Core\\Controller\\TitleCallback::example')
    ->willReturn($callable);
  $this->argumentResolver
    ->expects($this->once())
    ->method('getArguments')
    ->with($request, $callable)
    ->willReturn([
    $title,
  ]);
  $this->assertEquals($expected, $this->titleResolver
    ->getTitle($request, $route));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.