You are here

public function PathBasedBreadcrumbBuilderTest::testBuildWithException in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest::testBuildWithException()

Tests that exceptions during request matching are caught.

@covers ::build @covers ::getRequestForPath

@dataProvider providerTestBuildWithException

File

core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php, line 261
Contains \Drupal\Tests\system\Unit\Breadcrumbs\PathBasedBreadcrumbBuilderTest.

Class

PathBasedBreadcrumbBuilderTest
@coversDefaultClass \Drupal\system\PathBasedBreadcrumbBuilder @group system

Namespace

Drupal\Tests\system\Unit\Breadcrumbs

Code

public function testBuildWithException($exception_class, $exception_argument) {
  $this->context
    ->expects($this
    ->once())
    ->method('getPathInfo')
    ->will($this
    ->returnValue('/example/bar'));
  $this
    ->setupStubPathProcessor();
  $this->requestMatcher
    ->expects($this
    ->any())
    ->method('matchRequest')
    ->will($this
    ->throwException(new $exception_class($exception_argument)));
  $breadcrumb = $this->builder
    ->build($this
    ->getMock('Drupal\\Core\\Routing\\RouteMatchInterface'));

  // No path matched, though at least the frontpage is displayed.
  $this
    ->assertEquals([
    0 => new Link('Home', new Url('<front>')),
  ], $breadcrumb
    ->getLinks());
  $this
    ->assertEquals([
    'url.path',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}