summaryrefslogtreecommitdiffstats
path: root/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/system/src/Tests/System/TokenReplaceUnitTest.php')
-rw-r--r--core/modules/system/src/Tests/System/TokenReplaceUnitTest.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php
index f98c373..b8f31e7 100644
--- a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php
+++ b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php
@@ -9,6 +9,7 @@ namespace Drupal\system\Tests\System;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
+use Drupal\Core\Render\BubbleableMetadata;
/**
* Generates text using placeholders for dummy content to check token
@@ -111,12 +112,25 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
$tests['[site:url-brief]'] = preg_replace(array('!^https?://!', '!/$!'), '', \Drupal::url('<front>', [], $url_options));
$tests['[site:login-url]'] = \Drupal::url('user.page', [], $url_options);
+ $base_bubbleable_metadata = new BubbleableMetadata();
+
+ $metadata_tests = [];
+ $metadata_tests['[site:name]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
+ $metadata_tests['[site:slogan]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
+ $metadata_tests['[site:mail]'] = BubbleableMetadata::createFromObject(\Drupal::config('system.site'));
+ $bubbleable_metadata = clone $base_bubbleable_metadata;
+ $metadata_tests['[site:url]'] = $bubbleable_metadata->addCacheContexts(['url.site']);
+ $metadata_tests['[site:url-brief]'] = $bubbleable_metadata;
+ $metadata_tests['[site:login-url]'] = $bubbleable_metadata;
+
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
- $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId()));
+ $bubbleable_metadata = new BubbleableMetadata();
+ $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input)));
+ $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test unsanitized tokens.
@@ -124,7 +138,7 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
$tests['[site:slogan]'] = $config->get('slogan');
foreach ($tests as $input => $expected) {
- $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId(), 'sanitize' => FALSE));
+ $output = $this->tokenService->replace($input, array(), array('langcode' => $this->interfaceLanguage->getId(), 'sanitize' => FALSE), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input)));
}
@@ -133,10 +147,10 @@ class TokenReplaceUnitTest extends TokenReplaceUnitTestBase {
// flag is being passed properly through the call stack and being handled
// correctly by a 'known' token, [site:slogan].
$raw_tokens = array('slogan' => '[site:slogan]');
- $generated = $this->tokenService->generate('site', $raw_tokens);
+ $generated = $this->tokenService->generate('site', $raw_tokens, [], [], $bubbleable_metadata);
$this->assertEqual($generated['[site:slogan]'], $safe_slogan, 'Token sanitized.');
- $generated = $this->tokenService->generate('site', $raw_tokens, array(), array('sanitize' => FALSE));
+ $generated = $this->tokenService->generate('site', $raw_tokens, array(), array('sanitize' => FALSE), $bubbleable_metadata);
$this->assertEqual($generated['[site:slogan]'], $slogan, 'Unsanitized token generated properly.');
}