From bdbdee8d171c7fc3064d1ea00f27b9f74a714337 Mon Sep 17 00:00:00 2001
From: Arvin Singla <arvin.singla@freeformsolutions.ca>
Date: Fri, 11 Mar 2011 14:46:23 -0600
Subject: [PATCH] Issue #927570 by tedfordgif, arvinsingla: Re-rolled patch with simpletests included.

---
 modules/search/search.pages.inc |    2 +
 modules/search/search.test      |   43 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/modules/search/search.pages.inc b/modules/search/search.pages.inc
index 833ea8b..b0c12e5 100644
--- a/modules/search/search.pages.inc
+++ b/modules/search/search.pages.inc
@@ -40,6 +40,8 @@ function search_view($module = NULL, $keys = '') {
     if ($keys) {
       $path .= '/' . $keys;
     }
+    // Unset the destination to avoid redirect loops
+    unset($_GET['destination']);
     drupal_goto($path);
   }
 
diff --git a/modules/search/search.test b/modules/search/search.test
index 4d37133..106fb56 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -1947,3 +1947,46 @@ class SearchLanguageTestCase extends DrupalWebTestCase {
     $this->assertNoText(t('Languages'), t('No languages to choose from.'));
   }
 }
+
+/**
+ * Tests search page is accessible when set as error pages
+ */
+class SearchPageError extends DrupalWebTestCase {
+
+  public $search_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Search page /search as error 404 and 403 errors ',
+      'description' => 'Verify that the search page redirects properly when set as the 404/403 error pages',
+      'group' => 'Search',
+    );
+  }
+
+  /**
+   * Implementation setUp().
+   */
+  function setUp() {
+    parent::setUp('search');
+    $this->privileged_user = $this->drupalCreateUser(array('search content'));
+    $this->drupalLogin($this->privileged_user);
+  }
+  
+  /**
+   * Test for 404 case
+   */
+  public function testSearchError404() {
+    variable_set("site_404", 'search');
+    $this->drupalGet($this->randomName(8));
+    $this->assertText(t('Search'), t('Make sure we are on the search page.'));
+  }
+  
+  /**
+   * Test the 403 case
+   */
+  public function testSearchError403() {
+    variable_set("site_403", 'search');
+    $this->drupalGet('node/add'); // Going to a page a user would not have access to
+    $this->assertText(t('Search'), t('Make sure we are on the search page.'));
+  }
+}
\ No newline at end of file
-- 
1.7.2.3

