1 token.test TokenReplaceTestCase::testSystemSiteTokenReplacement()

Tests the generation of all system site information tokens.

File

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

Class

TokenReplaceTestCase
Test token replacement in strings.

Code

function testSystemSiteTokenReplacement() {
  global $language;
  $url_options = array(
    'absolute' => TRUE,
    'language' => $language,
  );

  // Set a few site variables.
  config('system.core')
    ->set('site_name', '<strong>Backdrop<strong>')
    ->set('site_slogan', '<blink>Slogan</blink>')
    ->save();

  // Generate and test sanitized tokens.
  $tests = array();
  $tests['[site:name]'] = check_plain(config_get_translated('system.core', 'site_name'));
  $tests['[site:slogan]'] = check_plain(config_get_translated('system.core', 'site_slogan'));
  $tests['[site:mail]'] = 'simpletest@example.com';
  $tests['[site:url]'] = url('<front>', $url_options);
  $tests['[site:url-brief]'] = preg_replace(array('!^https?://!', '!/$!'), '', url('<front>', $url_options));
  $tests['[site:url:brief]'] = $tests['[site:url-brief]'];
  $tests['[site:login-url]'] = url('user', $url_options);

  // 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_replace($input, array(), array('language' => $language));
    $this->assertEqual($output, $expected, format_string('Sanitized system site information token %token replaced.', array('%token' => $input)));
  }

  // Generate and test unsanitized tokens.
  $tests['[site:name]'] = config_get_translated('system.core', 'site_name');
  $tests['[site:slogan]'] = config_get_translated('system.core', 'site_slogan');

  foreach ($tests as $input => $expected) {
    $output = token_replace($input, array(), array('language' => $language, 'sanitize' => FALSE));
    $this->assertEqual($output, $expected, format_string('Unsanitized system site information token %token replaced.', array('%token' => $input)));
  }
}