I've recently been working on writing tests for a Catalyst app using
Test::WWW::Mechanize::
Catalyst. Unfortunately, I've hit a snag; Catalyst::Test's local_request()
method (which is used by Test::WWW::Mechanize::Catalyst) does not parse the
base href=... tag in the content of the response. This means that the
Mechanize object can't follow links properly.
The documentation for $r-base in HTTP::Response states:
The base URI is obtained from one the following sources (in
priority order):
1. Embedded in the document content, for instance BASE
HREF=... in HTML documents.
...
When the LWP protocol modules produce the HTTP::Response object,
then any base URI embedded in the document (step 1) will already
have initialized the Content-Base: header. This means that this
method only performs the last 2 steps...
Looking inside LWP::UserAgent, I see that it does indeed have code that uses
HTML::HeadParser to parse the html head and set headers in the response
accordingly.
However, Catalyst::Test does not use LWP::UserAgent in local_request(), and
it doesn't use HTML::HeadParser itself, so it's not setting the response's
content-base header for the base href=... tag.
I've attached a test app with test files to demonstrate the problem. (The
app is just the initial app created by catalyst.pl, with a simple test
action added that inserts a base href=... tag into the welcome message.
Also, I deleted the images to make the attachment smaller.)
Test fails with Catalyst::Test doing local_request():
% perl base_ct.t
ok 1 - GET /test
ok 2 - Got base href
# Base href = http://localhost/
not ok 3 - Response base matches base href
# Failed test 'Response base matches base href'
# at base_ct.t line 18.
# got: 'http://localhost/test'
# expected: 'http://localhost/'
1..3
# Looks like you failed 1 test of 3.
Test succeeds with Catalyst::Test doing remote_request():
% CATALYST_SERVER=http://localhost:3000/ perl base_ct.t
ok 1 - GET /test
ok 2 - Got base href
# Base href = http://localhost:3000/
ok 3 - Response base matches base href
1..3
Using Test::WWW::Mechanize::Catalyst succeeds or fails in the same way.
The only reference I found to this issue is a post to this mailing list from
2007, which no one answered. Has anyone else experienced this problem?
Would a patch that cribs some code from LWP::UserAgent and puts it in
Catalyst::Test local_request() be accepted?
Ronald
TestApp.tar.gz
Description: GNU Zip compressed data
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/