make uri_for unicode safe
[catagits/Catalyst-Runtime.git] / t / live_engine_request_uri.t
CommitLineData
5789a3d8 1\feff#!perl\r
fbcc39ad 2\r
3use strict;\r
4use warnings;\r
5\r
6use FindBin;\r
a2e038a1 7use lib "$FindBin::Bin/lib";\r
fbcc39ad 8\r
5789a3d8 9use Test::More tests => 38;\r
fbcc39ad 10use Catalyst::Test 'TestApp';\r
11use Catalyst::Request;\r
12\r
13my $creq;\r
14\r
15# test that the path can be changed\r
16{\r
17 ok( my $response = request('http://localhost/engine/request/uri/change_path'), 'Request' );\r
18 ok( $response->is_success, 'Response Successful 2xx' );\r
19 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
79f8efb8 20 like( $creq->uri, qr{/my/app/lives/here$}, 'URI contains new path' );\r
fbcc39ad 21}\r
22\r
23# test that path properly removes the base location\r
24{\r
25 ok( my $response = request('http://localhost/engine/request/uri/change_base'), 'Request' );\r
26 ok( $response->is_success, 'Response Successful 2xx' );\r
27 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
28 like( $creq->base, qr{/new/location}, 'Base URI contains new location' );\r
29 is( $creq->path, 'engine/request/uri/change_base', 'URI contains correct path' );\r
30}\r
31\r
32# test that base + path is correct\r
33{\r
34 ok( my $response = request('http://localhost/engine/request/uri'), 'Request' );\r
35 ok( $response->is_success, 'Response Successful 2xx' );\r
36 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
37 is( $creq->base . $creq->path, $creq->uri, 'Base + Path ok' );\r
38}\r
39\r
40# test that we can use semi-colons as separators\r
41{\r
42 my $parameters = {\r
43 a => [ qw/1 2/ ],\r
44 b => 3,\r
45 };\r
46 \r
47 ok( my $response = request('http://localhost/engine/request/uri?a=1;a=2;b=3'), 'Request' );\r
48 ok( $response->is_success, 'Response Successful 2xx' );\r
49 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
50 is( $creq->{uri}->query, 'a=1;a=2;b=3', 'Query string ok' );\r
51 is_deeply( $creq->{parameters}, $parameters, 'Parameters ok' );\r
e0616220 52}\r
53\r
54# test that query params are unescaped properly\r
55{\r
56 ok( my $response = request('http://localhost/engine/request/uri?text=Catalyst%20Rocks'), 'Request' );\r
57 ok( $response->is_success, 'Response Successful 2xx' );\r
58 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );\r
59 is( $creq->{uri}->query, 'text=Catalyst%20Rocks', 'Query string ok' );\r
60 is( $creq->{parameters}->{text}, 'Catalyst Rocks', 'Unescaped param ok' );\r
61}\r
bd917b94 62\r
63# test that uri_with adds params\r
64{\r
65 ok( my $response = request('http://localhost/engine/request/uri/uri_with'), 'Request' );\r
66 ok( $response->is_success, 'Response Successful 2xx' );\r
67 ok( !defined $response->header( 'X-Catalyst-Param-a' ), 'param "a" ok' );\r
68 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
69}\r
70\r
71# test that uri_with adds params (and preserves)\r
72{\r
73 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1'), 'Request' );\r
74 ok( $response->is_success, 'Response Successful 2xx' );\r
75 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );\r
76 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
77}\r
78\r
79# test that uri_with replaces params (and preserves)\r
80{\r
81 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2'), 'Request' );\r
82 ok( $response->is_success, 'Response Successful 2xx' );\r
83 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );\r
84 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );\r
85}\r
5789a3d8 86\r
87# test that uri_with is utf8 safe\r
88{\r
89 ok( my $response = request("http://localhost/engine/request/uri/uri_with_utf8"), 'Request' );\r
90 ok( $response->is_success, 'Response Successful 2xx' );\r
91 like( $response->header( 'X-Catalyst-uri-with' ), qr/%E2%98%A0$/, 'uri_with ok' );\r
92}\r