function TitleClosureTest::testTitleClosureRoundTrip

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/Core/Routing/TitleClosureTest.php \Drupal\KernelTests\Core\Routing\TitleClosureTest::testTitleClosureRoundTrip()

Tests that a title closure survives being written to the router table.

File

core/tests/Drupal/KernelTests/Core/Routing/TitleClosureTest.php, line 37

Class

TitleClosureTest
Tests title closures declared on Route attributes.

Namespace

Drupal\KernelTests\Core\Routing

Code

public function testTitleClosureRoundTrip() : void {
  $route = $this->container
    ->get('router.route_provider')
    ->getRouteByName('router_test.title_closure');
  // The closure is not stored on the route, only a reference to it.
  $this->assertNull($route->getDefault('_title'));
  $this->assertSame([
    TestAttributes::class,
    'titleClosure',
    0,
  ], $route->getDefault('_title_closure'));
  $request = new Request();
  $request->attributes
    ->set('parameter', 'test');
  $title = $this->container
    ->get('title_resolver')
    ->getTitle($request, $route);
  $this->assertSame('First title for test', (string) $title);
}

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