You are here

public function PathBasedBreadcrumbBuilderTest::testBuildWithThreePathElements in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 208
Contains \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest.

Class

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

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

public function testBuildWithThreePathElements() {
  $this->context
    ->expects($this
    ->once())
    ->method('getPathInfo')
    ->will($this
    ->returnValue('/example/bar/baz'));
  $this
    ->setupStubPathProcessor();
  $route_1 = new Route('/example/bar');
  $route_2 = new Route('/example');
  $this->requestMatcher
    ->expects($this
    ->exactly(2))
    ->method('matchRequest')
    ->will($this
    ->returnCallback(function (Request $request) use ($route_1, $route_2) {
    if ($request
      ->getPathInfo() == '/example/bar') {
      return array(
        RouteObjectInterface::ROUTE_NAME => 'example_bar',
        RouteObjectInterface::ROUTE_OBJECT => $route_1,
        '_raw_variables' => new ParameterBag(array()),
      );
    }
    elseif ($request
      ->getPathInfo() == '/example') {
      return array(
        RouteObjectInterface::ROUTE_NAME => 'example',
        RouteObjectInterface::ROUTE_OBJECT => $route_2,
        '_raw_variables' => new ParameterBag(array()),
      );
    }
  }));
  $this->accessManager
    ->expects($this
    ->any())
    ->method('check')
    ->willReturnOnConsecutiveCalls(AccessResult::allowed()
    ->cachePerPermissions(), AccessResult::allowed()
    ->addCacheContexts([
    'bar',
  ])
    ->addCacheTags([
    'example',
  ]));
  $breadcrumb = $this->builder
    ->build($this
    ->getMock('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
    ->assertEquals([
    'bar',
    'url.path',
    'user.permissions',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([
    'example',
  ], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}