You are here

public function ForumBreadcrumbBuilderBaseTest::testBuild in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/forum/tests/src/Unit/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php \Drupal\Tests\forum\Unit\Breadcrumb\ForumBreadcrumbBuilderBaseTest::testBuild()

Tests ForumBreadcrumbBuilderBase::build().

@covers ::build

See also

\Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase::build()

File

core/modules/forum/tests/src/Unit/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php, line 88
Contains \Drupal\Tests\forum\Unit\Breadcrumb\ForumBreadcrumbBuilderBaseTest.

Class

ForumBreadcrumbBuilderBaseTest
@coversDefaultClass \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase @group forum

Namespace

Drupal\Tests\forum\Unit\Breadcrumb

Code

public function testBuild() {

  // Build all our dependencies, backwards.
  $forum_manager = $this
    ->getMockBuilder('Drupal\\forum\\ForumManagerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $prophecy = $this
    ->prophesize('Drupal\\taxonomy\\VocabularyInterface');
  $prophecy
    ->label()
    ->willReturn('Fora_is_the_plural_of_forum');
  $prophecy
    ->id()
    ->willReturn(5);
  $prophecy
    ->getCacheTags()
    ->willReturn([
    'taxonomy_vocabulary:5',
  ]);
  $prophecy
    ->getCacheContexts()
    ->willReturn([]);
  $prophecy
    ->getCacheMaxAge()
    ->willReturn(Cache::PERMANENT);
  $vocab_storage = $this
    ->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $vocab_storage
    ->expects($this
    ->any())
    ->method('load')
    ->will($this
    ->returnValueMap(array(
    array(
      'forums',
      $prophecy
        ->reveal(),
    ),
  )));
  $entity_manager = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityManagerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $entity_manager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->will($this
    ->returnValueMap(array(
    array(
      'taxonomy_vocabulary',
      $vocab_storage,
    ),
  )));
  $config_factory = $this
    ->getConfigFactoryStub(array(
    'forum.settings' => array(
      'vocabulary' => 'forums',
    ),
  ));

  // Build a breadcrumb builder to test.
  $breadcrumb_builder = $this
    ->getMockForAbstractClass('Drupal\\forum\\Breadcrumb\\ForumBreadcrumbBuilderBase', array(
    $entity_manager,
    $config_factory,
    $forum_manager,
  ));

  // Add a translation manager for t().
  $translation_manager = $this
    ->getStringTranslationStub();
  $breadcrumb_builder
    ->setStringTranslation($translation_manager);

  // Our empty data set.
  $route_match = $this
    ->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');

  // Expected result set.
  $expected = array(
    Link::createFromRoute('Home', '<front>'),
    Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
  );

  // And finally, the test.
  $breadcrumb = $breadcrumb_builder
    ->build($route_match);
  $this
    ->assertEquals($expected, $breadcrumb
    ->getLinks());
  $this
    ->assertEquals([
    'route',
  ], $breadcrumb
    ->getCacheContexts());
  $this
    ->assertEquals([
    'taxonomy_vocabulary:5',
  ], $breadcrumb
    ->getCacheTags());
  $this
    ->assertEquals(Cache::PERMANENT, $breadcrumb
    ->getCacheMaxAge());
}