Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.3
diff -u -p -r1.3 common.test
--- modules/simpletest/tests/common.test	21 Aug 2008 19:36:38 -0000	1.3
+++ modules/simpletest/tests/common.test	25 Aug 2008 16:25:54 -0000
@@ -137,3 +137,93 @@ class DrupalHTTPRequestTestCase extends 
     $this->assertEqual($unable_to_parse->error, 'unable to parse URL', t('Returned with unable to parse URL error.'));
   }
 }
+
+/**
+ * Test for format_date()
+ */
+class DrupalFormatDateTestCase extends DrupalWebTestCase {
+  /**
+    * Implementation of getInfo().
+    */
+  function getInfo() {
+    return array(
+      'name' => t('Drupal date formatting'),
+      'description' => t("Performs tests on Drupal's date format."),
+      'group' => t('System')
+    );
+  }
+
+  /**
+    * Implementation of setUp().
+    */
+  function setUp() {
+    $this->date_formats = array(
+      'short' => 'm -- d -- Y ---- H/i',
+      'med' => 'D, m d Y - H/i',
+      'long' => 'l, F_j, Y - H::i'
+    );
+
+    $this->current_time = time();
+
+    $this->date_format_types = array('small', 'large', 'medium');
+
+    parent::setUp();
+  }
+
+  function testFormatDate() {
+    global $user;
+    $real_user = $user;
+
+    $test_user = $this->drupalCreateUser(array('administer site configuration'));
+    $user = $test_user;
+    $this->drupalLogin($user);
+
+    $edit = array(
+      'date_format_short'          => 'custom',
+      'date_format_medium'         => 'custom',
+      'date_format_long'           => 'custom',
+      'date_format_short_custom'   => $this->date_formats['short'],
+      'date_format_medium_custom'  => $this->date_formats['med'],
+      'date_format_long_custom'    => $this->date_formats['long']
+    );
+
+    $this->drupalPost('admin/settings/date-time', $edit, t('Save configuration'));
+    $this->refreshVariables();
+
+    $edit = array('timezone' => '-21600');
+    $this->drupalPost('user/'. $user->uid .'/edit', $edit, t('Save'));
+    $user = user_load($user->uid);
+
+    $this->assertFormatDate();
+    $user = $real_user;
+
+    $edit = array(
+      'configurable_timezones' => 0,
+      'date_default_timezone' => '-21600'
+    );
+    $this->drupalPost('admin/settings/date-time', $edit, t('Save configuration'));
+    $this->refreshVariables();
+
+    $this->assertFormatDate();
+  }
+
+  function assertFormatDate() {
+    $localized_time = $this->current_time + -21600;
+    foreach ($this->date_format_types as $date_format) {
+      switch ($date_format) {
+        case 'small':
+          $date = gmdate($this->date_formats['short'], $localized_time);
+          break;
+        case 'large':
+          $date = gmdate($this->date_formats['long'], $localized_time);
+          break;
+        case 'medium':
+          $date = gmdate($this->date_formats['med'], $localized_time);
+          break;
+      }
+
+      $drupal_date = format_date($this->current_time, $date_format);
+      $this->assertEqual($date, $drupal_date);
+    }
+  }
+}
