You are here

public function PathBasedBreadcrumbBuilderTest::testBuildWithUserPath 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::testBuildWithUserPath()

Tests the breadcrumb for a user path.

@covers ::build @covers ::getRequestForPath

File

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

Class

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

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

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')
    ->will($this
    ->returnCallback(function (Request $request) use ($route_1) {
    if ($request
      ->getPathInfo() == '/user/1') {
      return array(
        RouteObjectInterface::ROUTE_NAME => 'user_page',
        RouteObjectInterface::ROUTE_OBJECT => $route_1,
        '_raw_variables' => new ParameterBag(array()),
      );
    }
  }));
  $this
    ->setupAccessManagerToAllow();
  $this->titleResolver
    ->expects($this
    ->once())
    ->method('getTitle')
    ->with($this
    ->anything(), $route_1)
    ->will($this
    ->returnValue('Admin'));
  $breadcrumb = $this->builder
    ->build($this
    ->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));
  $this
    ->assertEquals([
    0 => new Link('Home', new Url('<front>')),
    1 => new Link('Admin', new Url('user_page')),
  ], $breadcrumb
    ->getLinks());
  $this
    ->assertEquals([
    'url.path',
    'user.permissions',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}