You are here

public function BreadcrumbManagerTest::testBuildWithSingleBuilder in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest::testBuildWithSingleBuilder()
  2. 10 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 81

Class

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

Namespace

Drupal\Tests\Core\Breadcrumb

Code

public function testBuildWithSingleBuilder() {
  $builder = $this
    ->createMock('Drupal\\Core\\Breadcrumb\\BreadcrumbBuilderInterface');
  $links = [
    '<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
    ->createMock('Drupal\\Core\\Routing\\RouteMatchInterface');
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter')
    ->with('system_breadcrumb', $this->breadcrumb, $route_match, [
    '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());
}