You are here

function TokenReplaceTestCase::testSystemSiteTokenReplacement in Drupal 7

Tests the generation of all system site information tokens.

File

modules/system/system.test, line 2229
Tests for system.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.
  variable_set('site_name', '<strong>Drupal<strong>');
  variable_set('site_slogan', '<blink>Slogan</blink>');

  // Generate and test sanitized tokens.
  $tests = array();
  $tests['[site:name]'] = check_plain(variable_get('site_name', 'Drupal'));
  $tests['[site:slogan]'] = check_plain(variable_get('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: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]'] = variable_get('site_name', 'Drupal');
  $tests['[site:slogan]'] = variable_get('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,
    )));
  }
}