public function PathBasedBreadcrumbBuilderTest::testBuildWithUserPath in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithUserPath()
Tests the breadcrumb for a user path.
@covers ::build @covers ::getRequestForPath
File
- core/
modules/ system/ tests/ src/ Unit/ Breadcrumbs/ PathBasedBreadcrumbBuilderTest.php, line 357 - Contains \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest.
Class
- PathBasedBreadcrumbBuilderTest
- @coversDefaultClass \Drupal\system\PathBasedBreadcrumbBuilder @group system
Namespace
Drupal\Tests\system\Unit\BreadcrumbsCode
public function testBuildWithUserPath() {
$this->context
->expects($this
->once())
->method('getPathInfo')
->will($this
->returnValue('/user/1/edit'));
$this
->setupStubPathProcessor();
$route_1 = new Route('/user/1');
$this->requestMatcher
->expects($this
->exactly(1))
->method('matchRequest')
->willReturnCallback(function (Request $request) use ($route_1) {
if ($request
->getPathInfo() == '/user/1') {
return [
RouteObjectInterface::ROUTE_NAME => 'user_page',
RouteObjectInterface::ROUTE_OBJECT => $route_1,
'_raw_variables' => new ParameterBag([]),
];
}
});
$this
->setupAccessManagerToAllow();
$this->titleResolver
->expects($this
->once())
->method('getTitle')
->with($this
->anything(), $route_1)
->will($this
->returnValue('Admin'));
$breadcrumb = $this->builder
->build($this
->createMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
$this
->assertEquals([
0 => new Link('Home', new Url('<front>')),
1 => new Link('Admin', new Url('user_page')),
], $breadcrumb
->getLinks());
$this
->assertEqualsCanonicalizing([
'url.path.is_front',
'url.path.parent',
'user.permissions',
], $breadcrumb
->getCacheContexts());
$this
->assertEqualsCanonicalizing([], $breadcrumb
->getCacheTags());
$this
->assertEquals(Cache::PERMANENT, $breadcrumb
->getCacheMaxAge());
}