You are here

public function PathBasedBreadcrumbBuilderTest::testBuildWithTwoPathElements in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithTwoPathElements()

Tests the build method with two path elements.

@covers ::build @covers ::getRequestForPath

File

core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php, line 182
Contains \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest.

Class

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

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

public function testBuildWithTwoPathElements() {
  $this->context
    ->expects($this
    ->once())
    ->method('getPathInfo')
    ->will($this
    ->returnValue('/example/baz'));
  $this
    ->setupStubPathProcessor();
  $route_1 = new Route('/example');
  $this->requestMatcher
    ->expects($this
    ->exactly(1))
    ->method('matchRequest')
    ->will($this
    ->returnCallback(function (Request $request) use ($route_1) {
    if ($request
      ->getPathInfo() == '/example') {
      return [
        RouteObjectInterface::ROUTE_NAME => 'example',
        RouteObjectInterface::ROUTE_OBJECT => $route_1,
        '_raw_variables' => new ParameterBag([]),
      ];
    }
  }));
  $this
    ->setupAccessManagerToAllow();
  $breadcrumb = $this->builder
    ->build($this
    ->createMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
  $this
    ->assertEquals([
    0 => new Link('Home', new Url('<front>')),
    1 => new Link('Example', new Url('example')),
  ], $breadcrumb
    ->getLinks());
  $this
    ->assertEquals([
    'url.path.is_front',
    'url.path.parent',
    'user.permissions',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}