function BreadcrumbManagerTest::testBuildWithSingleBuilder

Same name in other branches
  1. 9 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()
  3. 11.x 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.