Fixing your unit tests

You know that thing that happens when you love writing unit tests so much that you completely forget the argument order of all the assert(Equals|InstanceOf) functions.

Yeah it does happen, I’m sure it is not just me 😉

You write everything in as $this->assertEquals( function_call(), 'expected string' ); and then you get really confused when phpunit tells you it expects the wrong result from the function you haven’t implemented yet and received the expected result.

You do!

Good, I managed to write tests the wrong way round for two days before I realised and I wasn’t looking forward to going through and correcting them all, but then I remembered the power of sed and started cooking a recipe up.

It turned out pretty simple: sed -i "s/\(.*assert[^(]*\)( \([^,]*\), \([^)]*\) );/\1( \3, \2 );/" file_of_tests.php.

What it does:

  • Capture the start of the line up to the call to the assert function in ‘\1’
  • Capture the two function arguments in ‘\2’ and ‘\3’
  • Rewrite the matched line with the arguments switched

That was fun!

Responsible security releases

It’s great to see that the habari guys are committed to security as well as functionality and are providing security updates for there pre-1.0 software.  It is a pity to see that they don’t disclose much in there security announcements.

For me, responsible open security practises should mean that as well as providing a quick response to security issues you provide enough detail about the issue to your users to allow them to make a judgement call about how important the upgrade is to them.  Do they need to do the upgrade immediately because the issue is easy to exploit or can it wait till the weekend when they have more time to ensure they have a backup and a plan for when the upgrade goes wrong.
Continue reading “Responsible security releases”

Debugging ajax problems with firebug.

Now WordPress 2.5 RC1 is out it the wild for testing we are receiving some reports of strange problems with some of the ajax functionality in the admin pages so I have prepared a quick tutorial to help people collect the relevant debugging information to help us investigate the problems.

Here is how to prepare:

  1. Install Firefox (if you don’t have it already!)
  2. Install firebug. This is the web debugging tool of choice.
  3. Load up the relevant WordPress admin page that is not working for you.

Continue reading “Debugging ajax problems with firebug.”

Query Child Of $Page – update to make it work for anyone apart from me!

It seems that back in Oct 2006 when I updated my site design to use a simple plugin to automate the page listing all my plugins I managed to zip up a non-working version of the code.  Thanks to Stephen Rider my incompetence has been discover and I have now released an updated version of the plugin which will actually work for other people!  If you have attempted in the past to use my query child of $page plugin and failed please head over to the page and download a working copy.