summaryrefslogtreecommitdiffstats
path: root/core/modules/file/src/Tests/FileTokenReplaceTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/file/src/Tests/FileTokenReplaceTest.php')
-rw-r--r--core/modules/file/src/Tests/FileTokenReplaceTest.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php
index f5f478a..2d289c4 100644
--- a/core/modules/file/src/Tests/FileTokenReplaceTest.php
+++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php
@@ -8,6 +8,7 @@
namespace Drupal\file\Tests;
use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Core\Render\BubbleableMetadata;
use Drupal\file\Entity\File;
/**
@@ -58,12 +59,31 @@ class FileTokenReplaceTest extends FileFieldTestBase {
$tests['[file:owner]'] = SafeMarkup::checkPlain(user_format_name($this->adminUser));
$tests['[file:owner:uid]'] = $file->getOwnerId();
+ $base_bubbleable_metadata = BubbleableMetadata::createFromObject($file);
+ $metadata_tests = [];
+ $metadata_tests['[file:fid]'] = $base_bubbleable_metadata;
+ $metadata_tests['[file:name]'] = $base_bubbleable_metadata;
+ $metadata_tests['[file:path]'] = $base_bubbleable_metadata;
+ $metadata_tests['[file:mime]'] = $base_bubbleable_metadata;
+ $metadata_tests['[file:size]'] = $base_bubbleable_metadata;
+ $metadata_tests['[file:url]'] = $base_bubbleable_metadata;
+ $bubbleable_metadata = clone $base_bubbleable_metadata;
+ $metadata_tests['[file:created]'] = $bubbleable_metadata->addCacheTags(['rendered']);
+ $metadata_tests['[file:created:short]'] = $bubbleable_metadata;
+ $metadata_tests['[file:changed]'] = $bubbleable_metadata;
+ $metadata_tests['[file:changed:short]'] = $bubbleable_metadata;
+ $bubbleable_metadata = clone $base_bubbleable_metadata;
+ $metadata_tests['[file:owner]'] = $bubbleable_metadata->addCacheTags(['user:2']);
+ $metadata_tests['[file:owner:uid]'] = $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 = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId()));
+ $bubbleable_metadata = new BubbleableMetadata();
+ $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input)));
+ $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test unsanitized tokens.