7 use lib "$FindBin::Bin/lib";
9 use Test::More tests => 49;
10 use Catalyst::Test 'TestApp';
11 use Catalyst::Request;
15 # test that the path can be changed
17 ok( my $response = request('http://localhost/engine/request/uri/change_path'), 'Request' );
18 ok( $response->is_success, 'Response Successful 2xx' );
19 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
20 like( $creq->uri, qr{/my/app/lives/here$}, 'URI contains new path' );
23 # test that path properly removes the base location
25 ok( my $response = request('http://localhost/engine/request/uri/change_base'), 'Request' );
26 ok( $response->is_success, 'Response Successful 2xx' );
27 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
28 like( $creq->base, qr{/new/location}, 'Base URI contains new location' );
29 is( $creq->path, 'engine/request/uri/change_base', 'URI contains correct path' );
32 # test that base + path is correct
34 ok( my $response = request('http://localhost/engine/request/uri'), 'Request' );
35 ok( $response->is_success, 'Response Successful 2xx' );
36 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
37 is( $creq->base . $creq->path, $creq->uri, 'Base + Path ok' );
40 # test base is correct for HTTPS URLs
43 if ( $ENV{CATALYST_SERVER} ) {
44 skip 'Using remote server', 5;
47 local $ENV{HTTPS} = 'on';
48 ok( my $response = request('https://localhost/engine/request/uri'), 'HTTPS Request' );
49 ok( $response->is_success, 'Response Successful 2xx' );
50 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
51 is( $creq->base, 'https://localhost/', 'HTTPS base ok' );
52 is( $creq->uri, 'https://localhost/engine/request/uri', 'HTTPS uri ok' );
55 # test that we can use semi-colons as separators
62 ok( my $response = request('http://localhost/engine/request/uri?a=1;a=2;b=3'), 'Request' );
63 ok( $response->is_success, 'Response Successful 2xx' );
64 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
65 is( $creq->{uri}->query, 'a=1;a=2;b=3', 'Query string ok' );
66 is_deeply( $creq->{parameters}, $parameters, 'Parameters ok' );
69 # test that query params are unescaped properly
71 ok( my $response = request('http://localhost/engine/request/uri?text=Catalyst%20Rocks'), 'Request' );
72 ok( $response->is_success, 'Response Successful 2xx' );
73 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
74 is( $creq->{uri}->query, 'text=Catalyst%20Rocks', 'Query string ok' );
75 is( $creq->{parameters}->{text}, 'Catalyst Rocks', 'Unescaped param ok' );
78 # test that uri_with adds params
80 ok( my $response = request('http://localhost/engine/request/uri/uri_with'), 'Request' );
81 ok( $response->is_success, 'Response Successful 2xx' );
82 ok( !defined $response->header( 'X-Catalyst-Param-a' ), 'param "a" ok' );
83 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
86 # test that uri_with adds params (and preserves)
88 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1'), 'Request' );
89 ok( $response->is_success, 'Response Successful 2xx' );
90 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
91 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
94 # test that uri_with replaces params (and preserves)
96 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2'), 'Request' );
97 ok( $response->is_success, 'Response Successful 2xx' );
98 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
99 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
102 # test that uri_with replaces params (and preserves)
104 ok( my $response = request('http://localhost/engine/request/uri/uri_with_object'), 'Request' );
105 ok( $response->is_success, 'Response Successful 2xx' );
106 like( $response->header( 'X-Catalyst-Param-a' ), qr(https?://localhost[^/]*/), 'param "a" ok' );
109 # test that uri_with is utf8 safe
111 ok( my $response = request("http://localhost/engine/request/uri/uri_with_utf8"), 'Request' );
112 ok( $response->is_success, 'Response Successful 2xx' );
113 like( $response->header( 'X-Catalyst-uri-with' ), qr/%E2%98%A0$/, 'uri_with ok' );
116 # test with undef -- no warnings should be thrown
118 ok( my $response = request("http://localhost/engine/request/uri/uri_with_undef"), 'Request' );
119 ok( $response->is_success, 'Response Successful 2xx' );
120 is( $response->header( 'X-Catalyst-warnings' ), 0, 'no warnings emitted' );