6098 comments
2357 subscribers
6260 on Twitter
Subscribe! Feed reader E-mail

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

Short URL: http://sachachua.com/blog/p/5005

On This Day...

  • 2012: Weekly review: Week ending July 27, 2012 — Tablet tablet tablet tablet tablet. =) From last week’s plans Business [X] Earn: E1: Revise training material, prototype communities [...]
  • 2011: Piano lesson week 2 — I’m starting to get the hang of the first part of the overture from “Raymond” and this bluesy sort of [...]
  • 2010: Electronic ears: Using Performous to learn how to sing — SCHEDULED: 2010-07-28 Wed 08:00 I’ve been singing in the wrong key(s) all my life. Thanks to Brendon Robinson’s [...]
  • 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

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!