sacha chua :: living an awesome life

2134 blog subscribers
2747 on Twitter
Subscribe!
E-mail Feed reader

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…)

So-soHmmGoodGreatAwesome! (No Ratings Yet)
Loading ... Loading ...
Save to - del.icio.us - Digg it - reddit - StumbleUpon -

3 Responses to “Drupal: Patching simpletest for Drupal 5 to understand the Location header”

  1. Do you have a link to the issue on d.o. where we can review this patch?

  2. Hi Sacha! You might want to use the wp-syntax plugin for this blog to highlight your PHP codes.

  3. [...] was also happy with some of the infrastructure I built and the tests I added at work. Kaizen! [...]

Discussion Area - Leave a Comment

Please comment as you, not your organization.





On This Day...

  • 2009: Taro — I joined other recent hires for an evening out that ended up at a bubble tea shop. I ordered taro [...]
  • 2009: Sewing arghs — I’m temporarily finding sewing frustrating. I should be precise: sewing dresses and blouses is frustrating for me, because the bodice [...]
  • 2008: Kaizen: What would make our Drupal lives better? — Kaizen: relentless improvement. We’re getting ready for the next phase of our Drupal project, and it’s a good time to think [...]
  • 2008: Emacs, Remember, and GTD — Charles Cave has written an excellent Remember Mode Tutorial with useful templates for notes, receipts, books read, daily reviews, and [...]
  • 2007: Park play; A Midsummer Night’s Dream — More exercise at the park today. I did three sets of five assisted chin-ups and assorted other exercises, although I still [...]
  • 2007: I am going to have it all — I have decided to do extraordinarily well, and to live the fullest life I can. That means a rich and fulfilling [...]
  • 2005: Custom planner =) — I went to a shop specializing in pens and organizers, but I couldn’t find anything that matched what I had in [...]
  • 2005: You’ve got a friend… — I’ve just finished watching the video my friends made for my birthday and send-off party, and now that I’ve recovered my breath [...]
  • 2005: Competition: Build a PC in the fastest time and be crowned as the Philippines’ FASTEST GEEK! — Thanks to Marcelle for passing on the word! Build a PC in the fastest time and be crowned as the Philippines’ [...]
  • 2005: Zero Gravity Circus — I biked over to 1300 Gerrard Street East to join the weekly Zero Gravity Circus practice (7 – 11, Wednesdays). [...]
  • 2004: Japanese test! Monday! At 2! — Eeeeeek!
  • 2004: And then there were two — Apparently, we’re down to two candidates from the Philippines. I feel like I’m on Survivor.
  • 2003: Persons With Disability Waiting to Feel ICT’s Impact — By Nina Somera Posted 18 June 2003 While most segments of the Philippine society has already felt the benefits brought by the advances [...]
  • 2003: Interesting mail stats — I ran gnus-stat.el on my mail.misc mailbox and these stats came up: (my name appears because I gcc myself) Total number of [...]
  • 2003: Swish-E and Gnus — swish-e -i . -N ~/Mail/index.swish -f ~/Mail/index.incremental -e -v 2 swish-e -M index.swish index.incremental index.tmp mv index.tmp index.swish