function PageContextTest::testBuildWhenNoEntityOnRoute

Tests the build method when no entity is present on the route.

File

core/modules/navigation/tests/src/Unit/PageContextTest.php, line 45

Class

PageContextTest
Tests the PageContext Top Bar item build output.

Namespace

Drupal\Tests\navigation\Unit

Code

public function testBuildWhenNoEntityOnRoute() : void {
  $route_helper = $this->prophesize(EntityRouteHelper::class);
  $route_helper->getContentEntityFromRoute()
    ->willReturn(NULL);
  $entity_repository = $this->prophesize(EntityRepositoryInterface::class)
    ->reveal();
  $moderation_information = $this->prophesize(ModerationInformationInterface::class)
    ->reveal();
  $plugin = new PageContext([], 'page_context', [], $route_helper->reveal(), $entity_repository, $moderation_information);
  $build = $plugin->build();
  $this->assertSame([
    '#cache' => [
      'contexts' => [
        'route',
      ],
    ],
  ], $build);
}

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