You are here

public function BreadcrumbManagerTest::testBuildWithSingleBuilder in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest::testBuildWithSingleBuilder()

Tests the build method with a single breadcrumb builder.

File

core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php, line 86
Contains \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest.

Class

BreadcrumbManagerTest
@coversDefaultClass \Drupal\Core\Breadcrumb\BreadcrumbManager @group Breadcrumb

Namespace

Drupal\Tests\Core\Breadcrumb

Code

public function testBuildWithSingleBuilder() {
  $builder = $this
    ->getMock('Drupal\\Core\\Breadcrumb\\BreadcrumbBuilderInterface');
  $links = array(
    '<a href="/example">Test</a>',
  );
  $this->breadcrumb
    ->setLinks($links);
  $this->breadcrumb
    ->addCacheContexts([
    'foo',
  ])
    ->addCacheTags([
    'bar',
  ]);
  $builder
    ->expects($this
    ->once())
    ->method('applies')
    ->will($this
    ->returnValue(TRUE));
  $builder
    ->expects($this
    ->once())
    ->method('build')
    ->willReturn($this->breadcrumb);
  $route_match = $this
    ->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter')
    ->with('system_breadcrumb', $this->breadcrumb, $route_match, array(
    'builder' => $builder,
  ));
  $this->breadcrumbManager
    ->addBuilder($builder, 0);
  $breadcrumb = $this->breadcrumbManager
    ->build($route_match);
  $this
    ->assertEquals($links, $breadcrumb
    ->getLinks());
  $this
    ->assertEquals([
    'foo',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([
    'bar',
  ], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}