class HistoryTokensHooksTest
Tests for HistoryTokensHooks.
Attributes
#[CoversMethod(HistoryTokensHooks::class, 'tokenInfo')]
#[Group('history')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\history\Unit\HistoryTokensHooksTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of HistoryTokensHooksTest
File
-
core/
modules/ history/ tests/ src/ Unit/ HistoryTokensHooksTest.php, line 19
Namespace
Drupal\Tests\history\UnitView source
class HistoryTokensHooksTest extends UnitTestCase {
/**
* Tests that tokenInfo() handles missing comment module gracefully.
*/
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.