public function TokenReplaceUnitTest::testClear in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/System/TokenReplaceUnitTest.php \Drupal\system\Tests\System\TokenReplaceUnitTest::testClear()
Tests the clear parameter.
File
- core/
modules/ system/ src/ Tests/ System/ TokenReplaceUnitTest.php, line 65 - Contains \Drupal\system\Tests\System\TokenReplaceUnitTest.
Class
- TokenReplaceUnitTest
- Generates text using placeholders for dummy content to check token replacement.
Namespace
Drupal\system\Tests\SystemCode
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, array(), array(
'langcode' => $this->interfaceLanguage
->getId(),
'clear' => TRUE,
));
$this
->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
$target .= '[user:name]';
$target .= '[bogus:token]';
$result = $this->tokenService
->replace($source, array(), array(
'langcode' => $this->interfaceLanguage
->getId(),
));
$this
->assertEqual($target, $result, 'Valid tokens replaced while invalid tokens ignored.');
}