function BreadcrumbManagerTest::testBuildWithOneNotApplyingBuilders

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest::testBuildWithOneNotApplyingBuilders()
  2. 10 core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest::testBuildWithOneNotApplyingBuilders()
  3. 11.x core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php \Drupal\Tests\Core\Breadcrumb\BreadcrumbManagerTest::testBuildWithOneNotApplyingBuilders()

Tests multiple breadcrumb builders of which one returns NULL.

File

core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php, line 149

Class

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

Namespace

Drupal\Tests\Core\Breadcrumb

Code

public function testBuildWithOneNotApplyingBuilders() {
    $builder1 = $this->createMock('Drupal\\Core\\Breadcrumb\\BreadcrumbBuilderInterface');
    $builder1->expects($this->once())
        ->method('applies')
        ->willReturn(FALSE);
    $builder1->expects($this->never())
        ->method('build');
    $builder2 = $this->createMock('Drupal\\Core\\Breadcrumb\\BreadcrumbBuilderInterface');
    $links2 = [
        '<a href="/example2">Test2</a>',
    ];
    $this->breadcrumb
        ->setLinks($links2);
    $this->breadcrumb
        ->addCacheContexts([
        'baz',
    ])
        ->addCacheTags([
        'qux',
    ]);
    $builder2->expects($this->once())
        ->method('applies')
        ->willReturn(TRUE);
    $builder2->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' => $builder2,
    ]);
    $this->breadcrumbManager
        ->addBuilder($builder1, 10);
    $this->breadcrumbManager
        ->addBuilder($builder2, 0);
    $breadcrumb = $this->breadcrumbManager
        ->build($route_match);
    $this->assertEquals($links2, $breadcrumb->getLinks());
    $this->assertEquals([
        'baz',
    ], $breadcrumb->getCacheContexts());
    $this->assertEquals([
        'qux',
    ], $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.