Skip Menu |

This queue is for tickets about the Test-WWW-Mechanize-CGI CPAN distribution.

Report information
The Basics
Id: 28920
Status: open
Priority: 0/
Queue: Test-WWW-Mechanize-CGI

People
Owner: Nobody in particular
Requestors: NPW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.1
Fixed in: (no value)



Subject: problem with redirects, plus suggested solution
Hi, I've come across a problem where Test-WWW-Mechanize-CGI-0.1 doesn't follow HTTP redirects automatically in the way that Test::WWW::Mechanize does. I'm using v0.1 of the former, and v0.3 of the latter, with v3.29 of CGI.pm and perl v5.8.8 under Ubuntu Feisty Fawn Linux. To see the problem try running the test script twmc-bug.t. As attached, it loads Test::WWW::Mechanize::CGI, and the cgi script tries to do a redirect, which is not followed by the module and the resulting checks fail. Included is a workaround, CGI.pm defining My::Test::WWW::Mechanize::CGI, which overrides Test::WWW::Mechanize::CGI with a version of the simple_request method that redirects successfully. It should be quite easily refactor this back into the main module. To verify the fix works, modify the test script to use the workaround class. Thanks, otherwise the module did the job nicely. Nick Woolley ps Note, there's potentially a couple of other things which might help - not sure if they are issues with T::W::M::C or W::M::C. In the test script I define the environment variables SCRIPT_NAME and HTTP_USER_AGENT, since the former seems to be needed for the CGI->url method to return the correct script URL, and the latter seems to be needed to avoid a warning from the guts of CGI.pm (v3.29).
Subject: twmc-bug.t
Subject: CGI.pm
File Edit Options Buffers Tools Perl Help package My::Test::WWW::Mechanize::CGI; use strict; use warnings; use base 'Test::WWW::Mechanize::CGI'; # this is a hacky workaround to the problem with # Test::WWW::Mechanize::CGI v0.1 in that it # won't redirect automatically like WWW::Mechanize does. sub _make_request { shift->Test::WWW::Mechanize::_make_request(@_); } sub simple_request { my $self = shift; $self->SUPER::_make_request(@_); } 1;
Seems like one of the attachments (twmc-bug.t) isn't accessible, I'll try uploading it again:
On Tue Aug 21 06:02:54 2007, NPW wrote: Show quoted text
> Seems like one of the attachments (twmc-bug.t) isn't accessible, I'll > try uploading it again:
Didn't seem to work either. Here it is: #!/usr/bin/perl -w use strict; use CGI; use Test::More 'no_plan'; my $script_url_path = "/cgi-bin/test"; my $url = "http://www.server.nowhere$script_url_path"; # this applies the workaround for version 0.1 of Test::WWW::Mechanize::CGI # hardwired for the sake of demonstration my $mech_class = 0? #$Test::WWW::Mechanize::CGI::VERSION <= 0.1? 'My::Test::WWW::Mechanize::CGI' : 'Test::WWW::Mechanize::CGI'; use_ok $mech_class; my $mech = $mech_class->new(autocheck => 1); $mech->env(SCRIPT_NAME => $script_url_path, # this allows $q->url to work ok HTTP_USER_AGENT => ref $mech); # stops a warning about an 'uninitialised value' from CGI.pm my $redirected = 0; $mech->cgi(sub { my $q = CGI->new; if ($q->param('redirected')) { print $q->header, $q->start_html, $q->p("hello"), $q->end_html } else { print $q->redirect($q->url."?redirected=1"); $redirected = 1 } }); # test we get a basic response okay, with no content.yaml $mech->get_ok($url, "view the admin page with no arguments"); is($redirected, 1, "have been redirected"); my $output = $mech->response->content; like($output, qr!<p>hello</p>!, "content seems to be correct");