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	28 Aug 2008 16:22:47 -0000
@@ -137,3 +137,265 @@ 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() {
+    // create some arbitrary date formats other than default
+    $this->date_formats = array(
+      'short' => 'm -- d -- Y ---- H/i',
+      'medium' => 'D, m d Y - H/i',
+      'long' => 'l, F_j, Y - H::i'
+    );
+
+    // current time of server
+    $this->current_time = $_SERVER['REQUEST_TIME'];
+
+    // date format types
+    $this->date_format_types = array('small', 'large', 'medium');
+
+    parent::setUp();
+  }
+
+  function testFormatDate() {
+    // get our 'real' user 
+    global $user;
+
+    // store 'real' user so that we can become user later
+    $real_user = $user;
+
+    $test_user = $this->drupalCreateUser(array('administer site configuration'));
+    $this->drupalLogin($test_user);
+
+    // make test user the global $user so that tests use local time zone settings
+    $user = $test_user;
+
+    // set date and time settings to custom formats
+    $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['medium'],
+      'date_format_long_custom'    => $this->date_formats['long']
+    );
+
+    $this->drupalPost('admin/settings/date-time', $edit, t('Save configuration'));
+    $this->refreshVariables();
+
+    // set the local time zone of the test user to an arbitrary time zone
+    $edit = array('timezone' => '-21600');
+    $this->drupalPost('user/'. $user->uid .'/edit', $edit, t('Save'));
+
+    // reload the vales for the global $user
+    $user = user_load($user->uid);
+
+    $this->assertFormatDate(-21600);
+
+    // become the real user again who does not have a local time zone set
+    $user = $real_user;
+
+    // remove user ability to configure time zone and use system default
+    $edit = array(
+      'configurable_timezones' => 0,
+      'date_default_timezone' => -36000
+    );
+    $this->drupalPost('admin/settings/date-time', $edit, t('Save configuration'));
+    $this->refreshVariables();
+
+    $this->assertFormatDate(-36000);
+  }
+
+  /**
+   * Helper function: asserts that format_date creates same formated string as gmdate
+   */
+  function assertFormatDate($time_zone) {
+    // get the current system time and add the time zone
+    $localized_time = $this->current_time + $time_zone;
+
+    foreach ($this->date_format_types as $date_format) {
+      // use gmdate to create the date string based on the local time and cooresponding formats
+      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['medium'], $localized_time);
+          break;
+      }
+
+      // use format_date to create the date string based on the server time, time zone set by drupal, and cooresponding formats
+      $drupal_date = format_date($this->current_time, $date_format);
+
+      // format_date() should have same value as gmdate()
+      $this->assertEqual($date, $drupal_date);
+    }
+  }
+}
+
+/**
+ * Test for setting a custom page not found
+ */
+class DrupalCustomPageNotFoundTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+   function getInfo() {
+     return array(
+       'name' => t('Custom page not found'),
+       'description' => t("Performs tests on Drupal's custom page not found setting."),
+       'group' => t('System')
+     );
+   }
+
+   function testDrupalCustomPageNotFound() {
+     $user = $this->drupalCreateUser(array('administer site configuration'));
+     $this->drupalLogin($user);
+
+     // create the page for our 404
+     $node = $this->drupalCreateNode(array(
+       'type'   => 'page',
+       'title'  =>  $this->randomName(),
+       'body'   =>  'This is a custom 404 page'
+      ));
+
+    // set the drupal setting for the custom 404 page
+     $edit = array('site_404' => 'node/'. $node->nid);
+     $this->drupalPost('admin/settings/error-reporting', $edit, t('Save configuration'));
+
+     // log the admin user out
+     $this->drupalLogout();
+
+     // try to go to arbitrary page that should respond in 404
+     $this->drupalGet('example_test_page_404');
+
+     // if it is our 404 page created above then great
+     $this->assertResponse(404, 'Access denied code.');
+     $this->assertText($node->title, t('The custom page not found.'), t('System'));
+   }
+}
+
+/**
+ * Test for setting a custom access denied
+ */
+class DrupalCustomAccessDeniedTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+   function getInfo() {
+     return array(
+       'name' => t('Custom access denied'),
+       'description' => t("Performs tests on Drupal's custom access denied page."),
+       'group' => t('System')
+     );
+   }
+
+   function testDrupalCustomAccessDenied() {
+     $user = $this->drupalCreateUser(array('administer site configuration'));
+     $this->drupalLogin($user);
+
+     // create the page for our 403
+     $node = $this->drupalCreateNode(array(
+       'type'   => 'page',
+       'title'  =>  $this->randomName(),
+       'body'   =>  'This is a custom 403 page'
+      ));
+
+    // set the drupal setting for the custom 403 page
+     $edit = array('site_403' => 'node/'. $node->nid);
+     $this->drupalPost('admin/settings/error-reporting', $edit, t('Save configuration'));
+
+     // log the admin user out
+     $this->drupalLogout();
+
+     // try to go to arbitrary page that should respond in 404
+     $this->drupalGet('node/add/page');
+
+     // if it is our 403 page created above then great
+     $this->assertResponse(403, 'Access denied code.');
+     $this->assertText($node->title, t('The custom access denied.'));
+   }
+}
+
+/**
+ * Test for drupal_get_headers() returns correct headers
+ */
+class DrupalGetHeadersTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+   function getInfo() {
+     return array(
+       'name' => t('Drupal get headers'),
+       'description' => t("Performs tests on Drupal's get headers function."),
+       'group' => t('System')
+     );
+   }
+
+   function testDrupalGetHeaders() {
+     $user = $this->drupalCreateUser(array('administer site configuration'));
+     $this->drupalLogin($user);
+
+     // create a page so that the rss.xml will be generated as will the front page
+     $this->drupalCreateNode(array(
+       'type'    => 'page',
+       'title'   =>  $this->randomName(),
+       'body'    =>  'This is a blank page.',
+       'promote' => 1
+      ));
+
+     // set the cache because cache uses drupal_get_headers
+     $edit = array('cache' => CACHE_NORMAL);
+     $this->drupalPost('admin/settings/performance', $edit, t('Save configuration'));
+     $this->refreshVariables();
+
+     // just to make sure there are no caches already
+     cache_clear_all();
+
+     // log the admin user out, so that we can have cached pages
+     $this->drupalLogout();
+
+     $this->drupalGet('node');
+     $page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+     $this->drupalGet('node');
+     $cached_page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+
+     // check to see if the node page and the cached node page are equal
+     $this->assertEqual($page, $cached_page);
+
+     $this->drupalGet('rss.xml');
+     $page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+     $this->drupalGet('rss.xml');
+     $cached_page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+
+     // check to see if the rss.xml page and the cached rss.xml page equal
+     $this->assertEqual($page, $cached_page);
+
+     $this->drupalGet('rss.xml');
+     $page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+     $this->drupalGet('node');
+     $cached_page = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
+
+     // check to see if the rss.xml and node page are NOT equal
+     $this->assertNotEqual($page, $cached_page);
+   }
+}
\ No newline at end of file
