function TokenReplaceTestCase::testSystemDateTokenReplacement

Tests the generation of all system date tokens.

File

modules/system/system.test, line 2341

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->language);
    $tests['[date:medium]'] = format_date($date, 'medium', '', NULL, $language->language);
    $tests['[date:long]'] = format_date($date, 'long', '', NULL, $language->language);
    $tests['[date:custom:m/j/Y]'] = format_date($date, 'custom', 'm/j/Y', NULL, $language->language);
    $tests['[date:since]'] = format_interval(REQUEST_TIME - $date, 2, $language->language);
    $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,
        )));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.