CUFP
simon.proctor
snippet
<div class="Description">My web app (for IIS reasons) uses meta refreshes to redirect the user around. I test these redirects with the code below. I've used a regex as my refresh template is fixed and very, very simple. However, if yours isn't/aren't then you should replace the regex with a call to something like HTML::TokeParser.
<br><br>
<b>Update</b>: fixed silly mistake as hilighted below. Also fixed what was, for my test suite, a logic error. The final get call must be to $expected_url and not $url. If your test quite works differently then use $url instead :).</div>
<CODE>
sub meta_refresh
{
my $mech = shift;
my $expected_url = shift;
my $url;
if($mech->content() =~ /<meta http-equiv="refresh" content="0;url=([^"]*)"/)
{
$url = $1;
}
cmp_ok($expected_url, 'eq', $url, "The meta refresh returns the expected URL");
$mech->get( $expected_url );
ok($mech->success(), "URL loaded successfully");
}
</CODE>
So call it like this:
<code>
# Code to cause the refresh to appear not shown.
# Check the refresh and follow
meta_refresh($mech, '/index.cgi?rm=home');
</code>