/** * @covers ::replace * @dataProvider providerTestReplaceEscaping */ public function testReplaceEscaping($string, array $tokens, $expected) { $this->moduleHandler->expects($this->any())->method('invokeAll')->willReturnCallback(function ($type, $args) { return $args[2]['tokens']; }); $result = $this->token->replace($string, ['tokens' => $tokens]); $this->assertInternalType('string', $result); $this->assertEquals($expected, $result); }
/** * @covers ::replace * @covers ::replace */ public function testReplaceWithHookTokensAlterWithBubbleableMetadata() { $this->moduleHandler->expects($this->any())->method('invokeAll')->willReturn([]); $this->moduleHandler->expects($this->any())->method('alter')->willReturnCallback(function ($hook_name, array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata) { $replacements['[node:title]'] = 'hello world'; $bubbleable_metadata->addCacheContexts(['custom_context']); $bubbleable_metadata->addCacheTags(['node:1']); $bubbleable_metadata->setCacheMaxAge(10); }); $node = $this->prophesize('Drupal\\node\\NodeInterface'); $node->getCacheContexts()->willReturn([]); $node->getCacheTags()->willReturn([]); $node->getCacheMaxAge()->willReturn(14); $node = $node->reveal(); $bubbleable_metadata = new BubbleableMetadata(); $bubbleable_metadata->setCacheContexts(['current_user']); $bubbleable_metadata->setCacheMaxAge(12); $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()); }
public function testReplace() { $urls = [['UrlRewrite1'], ['UrlRewrite2']]; $this->storage->expects($this->once())->method('doReplace')->with($urls); $this->storage->replace($urls); }