X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_engine_request_uri.t;h=39e33450b9f09f0567748dc78b1242eea0207895;hb=63b6bc2ae4f28f60fb0a9f3f731a1f3f24cf18e2;hp=fe15e9d232404970dc5241e4b7e3df997c750e18;hpb=0ce22ad477633bd8a0cd0a9d85d255d9683e1ea7;p=catagits%2FCatalyst-Runtime.git diff --git a/t/live_engine_request_uri.t b/t/live_engine_request_uri.t index fe15e9d..39e3345 100644 --- a/t/live_engine_request_uri.t +++ b/t/live_engine_request_uri.t @@ -1,12 +1,10 @@ -#!perl - use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 54; +use Test::More tests => 66; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -120,12 +118,40 @@ SKIP: is( $response->header( 'X-Catalyst-warnings' ), 0, 'no warnings emitted' ); } +# more tests with undef - should be ignored +{ + my $uri = "http://localhost/engine/request/uri/uri_with_undef_only"; + my ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers + ok( my $response = request($uri), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + like( $response->header( 'X-Catalyst-uri-with' ), qr/$check$/, 'uri_with ok' ); + + # try with existing param + $uri = "$uri?x=1"; + ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers + $check =~ s/\?/\\\?/g; + ok( $response = request($uri), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + like( $response->header( 'X-Catalyst-uri-with' ), qr/$check$/, 'uri_with ok' ); +} -# test that query params are unescaped properly with '+' { - ok( my $response = request('http://localhost/engine/request/uri?text=C%2B%2B+lang'), 'Request' ); + my $uri = "http://localhost/engine/request/uri/uri_with_undef_ignore"; + my ($check) = $uri =~ m{^http://localhost(.+)}; # needed to work with remote servers + ok( my $response = request($uri), 'Request' ); ok( $response->is_success, 'Response Successful 2xx' ); - ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); - is( $creq->{uri}->query, 'text=C%2B%2B+lang', 'Query string ok' ); - is( $creq->{parameters}->{text}, 'C++ lang', 'Unescaped param has pluses in it' ); + like( $response->header( 'X-Catalyst-uri-with' ), qr/$check\?a=1/, 'uri_with ok' ); + + # remove an existing param + ok( $response = request("${uri}?b=1"), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + like( $response->header( 'X-Catalyst-uri-with' ), qr/$check\?a=1/, 'uri_with ok' ); + + # remove an existing param, leave one, and add a new one + ok( $response = request("${uri}?b=1&c=1"), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' ); + ok( !defined $response->header( 'X-Catalyst-Param-b' ),'param "b" ok' ); + is( $response->header( 'X-Catalyst-Param-c' ), '1', 'param "c" ok' ); } +