diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/simpletest/tests/common.test | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 4ea5cb4ce..905fe7cd0 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -864,3 +864,73 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase { } } +/** + * Tests for the format_date() function. + */ +class FormatDateUnitTest extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => t('Format date'), + 'description' => t('Test the format_date() function.'), + 'group' => t('System'), + ); + } + + function setUp() { + parent::setUp('locale'); + variable_set('configurable_timezones', 1); + variable_set('date_format_long', 'l, j. F Y - G:i'); + variable_set('date_format_medium', 'j. F Y - G:i'); + variable_set('date_format_short', 'Y M j - g:ia'); + variable_set('locale_custom_strings_es', array( + '' => array('Sunday' => 'domingo'), + 'Long month name' => array('March' => 'marzo'), + )); + $this->refreshVariables(); + } + + function testFormatDate() { + global $user, $language; + + $timestamp = strtotime('2007-03-26T00:00:00+00:00'); + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Sunday, 25-Mar-07 17:00:00 PDT', t('Test all parameters.')); + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'es'), 'domingo, 25-Mar-07 17:00:00 PDT', t('Test translated format.')); + $this->assertIdentical(format_date($timestamp, 'custom', '\\l, d-M-y H:i:s T', 'America/Los_Angeles', 'es'), 'l, 25-Mar-07 17:00:00 PDT', t('Test an escaped format string.')); + $this->assertIdentical(format_date($timestamp, 'custom', '\\\\l, d-M-y H:i:s T', 'America/Los_Angeles', 'es'), '\\domingo, 25-Mar-07 17:00:00 PDT', t('Test format containing backslash character.')); + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'Europe/London', 'en'), 'Monday, 26-Mar-07 01:00:00 BST', t('Test a different time zone.')); + + // Create an admin user and add Spanish language. + $admin_user = $this->drupalCreateUser(array('administer languages')); + $this->drupalLogin($admin_user); + $this->drupalPost('admin/international/language/add', array('langcode' => 'es'), t('Add language')); + + // Create a test user to carry out the tests. + $test_user = $this->drupalCreateUser(); + $this->drupalLogin($test_user); + $edit = array('language' => 'es', 'mail' => $test_user->mail, 'timezone' => 'America/Los_Angeles'); + $this->drupalPost('user/' . $test_user->uid . '/edit', $edit, t('Save')); + + // Disable session saving as we are about to modify the global $user. + drupal_save_session(FALSE); + + // Save the original user and language and then replace it with the test user and language. + $real_user = $user; + $user = user_load($test_user->uid, TRUE); + $real_language = $language->language; + $language->language = $user->language; + + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Sunday, 25-Mar-07 17:00:00 PDT', t('Test a different language.')); + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'Europe/London'), 'Monday, 26-Mar-07 01:00:00 BST', t('Test a different time zone.')); + $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T'), 'domingo, 25-Mar-07 17:00:00 PDT', t('Test custom date format.')); + $this->assertIdentical(format_date($timestamp, 'large'), 'domingo, 25. marzo 2007 - 17:00', t('Test long date format.')); + $this->assertIdentical(format_date($timestamp, 'medium'), '25. marzo 2007 - 17:00', t('Test medium date format.')); + $this->assertIdentical(format_date($timestamp, 'small'), '2007 Mar 25 - 5:00pm', t('Test short date format.')); + $this->assertIdentical(format_date($timestamp), '25. marzo 2007 - 17:00', t('Test default date format.')); + + // Restore the original user and language, and enable session saving. + $user = $real_user; + $language->language = $real_language; + drupal_save_session(TRUE); + } +} |