Drupal: Patching simpletest for Drupal 5 to understand the Location header

Automated testing is part of good programmer hygiene. I wanted to write tests for both functions and Web-based interfaces in our Drupal project, but one of the tests I wrote was always failing. Many prints and var_debugs later, I found out that it was because simpletest didn’t do anything with Location: headers, which happen when you drupal_goto an external site. Here’s a first pass at fixing that behavior – patch sites/all/modules/simpletest/simpletest/browser.php:

Index: browser.php
===================================================================
--- browser.php	(revision 753)
+++ browser.php	(working copy)
@@ -321,6 +321,22 @@

         $this->_history->recordEntry(
                 $this->_page->getUrl(),
                 $this->_page->getRequestData());
+        $counter = 0;
+        $url = $this->_page->_headers->_location;
+        if ($url) {
+          $url = &new SimpleURL($url);
+        }
+        while ($url && $counter < 10) {
+          $this->_page = &$this->_fetch($url, $parameters);
+          $this->_history->recordEntry(
+            $this->_page->getUrl(),
+            $this->_page->getRequestData());
+          $url = $this->_page->_headers->_location;
+          if ($url) {
+            $url = &new SimpleURL($url);
+          }
+          $counter++;
+        }
         return $this->_page->getRaw();
     }

(update: okay, let’s try diff syntax highlighting with wp-syntax…)

One Pingback/Trackback