function PathBasedBreadcrumbBuilderTest::testBuildWithThreePathElements

Same name in other branches
  1. 9 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithThreePathElements()
  2. 8.9.x core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithThreePathElements()
  3. 10 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithThreePathElements()

Tests the build method with three path elements.

@covers ::build @covers ::getRequestForPath

File

core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php, line 218

Class

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

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

public function testBuildWithThreePathElements() : void {
    $this->context
        ->expects($this->once())
        ->method('getPathInfo')
        ->willReturn('/example/bar/baz');
    $this->setupStubPathProcessor();
    $route_1 = new Route('/example/bar');
    $route_2 = new Route('/example');
    $this->requestMatcher
        ->expects($this->exactly(2))
        ->method('matchRequest')
        ->willReturnCallback(function (Request $request) use ($route_1, $route_2) {
        if ($request->getPathInfo() == '/example/bar') {
            return [
                RouteObjectInterface::ROUTE_NAME => 'example_bar',
                RouteObjectInterface::ROUTE_OBJECT => $route_1,
                '_raw_variables' => new InputBag([]),
            ];
        }
        elseif ($request->getPathInfo() == '/example') {
            return [
                RouteObjectInterface::ROUTE_NAME => 'example',
                RouteObjectInterface::ROUTE_OBJECT => $route_2,
                '_raw_variables' => new InputBag([]),
            ];
        }
    });
    $this->accessManager
        ->expects($this->any())
        ->method('check')
        ->willReturnOnConsecutiveCalls(AccessResult::allowed()->cachePerPermissions(), AccessResult::allowed()->addCacheContexts([
        'bar',
    ])
        ->addCacheTags([
        'example',
    ]));
    $breadcrumb = $this->builder
        ->build($this->createMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
    $this->assertEquals([
        new Link('Home', new Url('<front>')),
        new Link('Example', new Url('example')),
        new Link('Bar', new Url('example_bar')),
    ], $breadcrumb->getLinks());
    $this->assertEqualsCanonicalizing([
        'bar',
        'url.path.is_front',
        'url.path.parent',
        'user.permissions',
    ], $breadcrumb->getCacheContexts());
    $this->assertEqualsCanonicalizing([
        'example',
    ], $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.