1.20.x token.test TokenReplaceTestCase::testSystemTokenRecognition()

Test whether token-replacement works in various contexts.

File

modules/simpletest/tests/token.test, line 65
Test integration for the token module.

Class

TokenReplaceTestCase
Test token replacement in strings.

Code

function testSystemTokenRecognition() {
  global $language;

  // Generate prefixes and suffixes for the token context.
  $tests = array(
    array('prefix' => 'this is the ', 'suffix' => ' site'),
    array('prefix' => 'this is the', 'suffix' => 'site'),
    array('prefix' => '[', 'suffix' => ']'),
    array('prefix' => '', 'suffix' => ']]]'),
    array('prefix' => '[[[', 'suffix' => ''),
    array('prefix' => ':[:', 'suffix' => '--]'),
    array('prefix' => '-[-', 'suffix' => ':]:'),
    array('prefix' => '[:', 'suffix' => ']'),
    array('prefix' => '[site:', 'suffix' => ':name]'),
    array('prefix' => '[site:', 'suffix' => ']'),
  );

  // Check if the token is recognized in each of the contexts.
  foreach ($tests as $test) {
    $input = $test['prefix'] . '[site:name]' . $test['suffix'];
    $expected = $test['prefix'] . 'Backdrop CMS' . $test['suffix'];
    $output = token_replace($input, array(), array('language' => $language));
    $this->assertTrue($output == $expected, format_string('Token recognized in string %string', array('%string' => $input)));
  }
}