diff --git a/CHANGES b/CHANGES index 825892a22..b24d68e83 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,8 @@ Revision history for Dancer (Yanick Champoux, reported by sciurius) * GH #954: don't die on autoflush for older perls. (Yanick Champoux, reported by metateck and David Golden) + * GH #950: Dancer::Test functions now populate REQUEST_URI. + (Yanick Champoux, reported by Sören Kornetzki) [ DOCUMENTATION ] * GH #942: simpilify the Apache deployment docs for cgi/fcgi. diff --git a/lib/Dancer/Test.pm b/lib/Dancer/Test.pm index 404fde945..a8df7f723 100644 --- a/lib/Dancer/Test.pm +++ b/lib/Dancer/Test.pm @@ -361,6 +361,17 @@ sub dancer_response { $extra_env->{'CONTENT_TYPE'} = $headers->header('Content-Type'); } + # fake the REQUEST_URI + # TODO deal with the params + unless( $extra_env->{REQUEST_URI} ) { + $extra_env->{REQUEST_URI} = $path; + if ( $method eq 'GET' and $params ) { + $extra_env->{REQUEST_URI} .= + '?' . join '&', map { join '=', $_, $params->{$_} } + sort keys %$params; + } + } + my $request = Dancer::Request->new_for_request( $method => $path, $params, $body, $headers, $extra_env diff --git a/t/23_dancer_tests/03_uris.t b/t/23_dancer_tests/03_uris.t new file mode 100644 index 000000000..78d3741f6 --- /dev/null +++ b/t/23_dancer_tests/03_uris.t @@ -0,0 +1,18 @@ +use strict; +use warnings; + +use Test::More tests => 5; + +use Dancer ':tests'; +use Dancer::Test; + +get '/uri_base' => sub { request->uri_base }; +get '/uri' => sub { request->uri }; +get '/path' => sub { request->path }; + +response_content_is '/uri_base' => 'http://localhost'; +response_content_is '/uri' => '/uri'; +response_content_is '/uri?with=params' => '/uri?with=params'; +response_content_is '/path' => '/path'; +response_content_is '/path?with=params' => '/path'; +