public function TokenReplaceKernelTest::testClear in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php \Drupal\Tests\system\Kernel\Token\TokenReplaceKernelTest::testClear()
- 9 core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php \Drupal\Tests\system\Kernel\Token\TokenReplaceKernelTest::testClear()
Tests the clear parameter.
File
- core/
modules/ system/ tests/ src/ Kernel/ Token/ TokenReplaceKernelTest.php, line 61
Class
- TokenReplaceKernelTest
- Generates text using placeholders for dummy content to check token replacement.
Namespace
Drupal\Tests\system\Kernel\TokenCode
public function testClear() {
// Valid token.
$source = '[site:name]';
// No user passed in, should be untouched.
$source .= '[user:name]';
// Non-existing token.
$source .= '[bogus:token]';
// Replace with the clear parameter, only the valid token should remain.
$target = Html::escape($this
->config('system.site')
->get('name'));
$result = $this->tokenService
->replace($source, [], [
'langcode' => $this->interfaceLanguage
->getId(),
'clear' => TRUE,
]);
$this
->assertEquals($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
$target .= '[user:name]';
$target .= '[bogus:token]';
$result = $this->tokenService
->replace($source, [], [
'langcode' => $this->interfaceLanguage
->getId(),
]);
$this
->assertEquals($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
}