function PathBasedBreadcrumbBuilderTest::testBuildWithUserPath

Same name in other branches
  1. 9 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithUserPath()
  2. 8.9.x core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithUserPath()
  3. 11.x 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 376

Class

PathBasedBreadcrumbBuilderTest
@coversDefaultClass \Drupal\system\PathBasedBreadcrumbBuilder @group system

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

public function testBuildWithUserPath() : void {
    $this->context
        ->expects($this->once())
        ->method('getPathInfo')
        ->willReturn('/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 InputBag([]),
            ];
        }
    });
    $this->setupAccessManagerToAllow();
    $this->titleResolver
        ->expects($this->once())
        ->method('getTitle')
        ->with($this->anything(), $route_1)
        ->willReturn('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());
}

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