public function TokenTest::testReplaceWithBubbleableMetadataObject in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::testReplaceWithBubbleableMetadataObject()
@covers ::replace
File
- core/
tests/ Drupal/ Tests/ Core/ Utility/ TokenTest.php, line 152
Class
- TokenTest
- @coversDefaultClass \Drupal\Core\Utility\Token @group Utility
Namespace
Drupal\Tests\Core\UtilityCode
public function testReplaceWithBubbleableMetadataObject() {
$this->moduleHandler
->expects($this
->any())
->method('invokeAll')
->willReturn([
'[node:title]' => 'hello world',
]);
$bubbleable_metadata = new BubbleableMetadata();
$bubbleable_metadata
->setCacheContexts([
'current_user',
]);
$bubbleable_metadata
->setCacheMaxAge(12);
$node = $this
->prophesize('Drupal\\node\\NodeInterface');
$node
->getCacheTags()
->willReturn([
'node:1',
]);
$node
->getCacheContexts()
->willReturn([
'custom_context',
]);
$node
->getCacheMaxAge()
->willReturn(10);
$node = $node
->reveal();
$result = $this->token
->replace('[node:title]', [
'node' => $node,
], [], $bubbleable_metadata);
$this
->assertEquals('hello world', $result);
$this
->assertEquals([
'node:1',
], $bubbleable_metadata
->getCacheTags());
$this
->assertEquals([
'current_user',
'custom_context',
], $bubbleable_metadata
->getCacheContexts());
$this
->assertEquals(10, $bubbleable_metadata
->getCacheMaxAge());
}