? page_not_found_access_denied_drupal_get_headers.patch
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 05:55:30 -0000
@@ -137,3 +137,241 @@ 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);
+    }
+  }
+}
+
+/**
+ * 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
