1 token.test TokenReplaceTestCase::testSystemDateTokenReplacement()

Tests the generation of all system date tokens.

File

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

Class

TokenReplaceTestCase
Test token replacement in strings.

Code

function testSystemDateTokenReplacement() {
  global $language;

  // Set time to one hour before request.
  $date = REQUEST_TIME - 3600;

  // Generate and test tokens.
  $tests = array();
  $tests['[date:short]'] = format_date($date, 'short', '', NULL, $language->langcode);
  $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $language->langcode);
  $tests['[date:long]'] = format_date($date, 'long', '', NULL, $language->langcode);
  $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $language->langcode);
  $tests['[date:since]'] = format_interval((REQUEST_TIME - $date), 2, $language->langcode);
  $tests['[date:raw]'] = filter_xss($date);

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