function HistoryTokensHooksTest::testTokenInfoWithoutCommentModuleInstalled

Tests that tokenInfo() handles missing comment module gracefully.

File

core/modules/history/tests/src/Unit/HistoryTokensHooksTest.php, line 26

Class

HistoryTokensHooksTest
Tests for HistoryTokensHooks.

Namespace

Drupal\Tests\history\Unit

Code

public function testTokenInfoWithoutCommentModuleInstalled() : void {
  // Create a mock entity type that implements ContentEntityInterface.
  $entityType = $this->createMock(EntityTypeInterface::class);
  $entityType->expects($this->once())
    ->method('entityClassImplements')
    ->with(ContentEntityInterface::class)
    ->willReturn(TRUE);
  // Create a mock entity type manager that returns our entity type.
  $entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
  $entityTypeManager->expects($this->once())
    ->method('getDefinitions')
    ->willReturn([
    'node' => $entityType,
  ]);
  // Create a container WITHOUT the comment module (service) installed.
  $container = new ContainerBuilder();
  $container->set('entity_type.manager', $entityTypeManager);
  \Drupal::setContainer($container);
  // Create the hooks class.
  $historyTokensHooks = new HistoryTokensHooks();
  $result = $historyTokensHooks->tokenInfo();
  $this->assertEquals([
    'tokens' => [],
  ], $result);
}

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