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. 8.9.x 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 85

Class

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

Namespace

Drupal\Tests\Core\Breadcrumb

Code

public function testBuildWithSingleBuilder() : void {
    $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')
        ->willReturn(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.