Commit | Line | Data |
c7ded7aa |
1 | \feff#!perl |
d0f0fcf6 |
2 | |
c7ded7aa |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
7 | use lib "$FindBin::Bin/lib"; |
8 | |
4668cab5 |
9 | use Test::More tests => 49; |
c7ded7aa |
10 | use Catalyst::Test 'TestApp'; |
11 | use Catalyst::Request; |
12 | |
13 | my $creq; |
14 | |
15 | # test that the path can be changed |
16 | { |
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' ); |
21 | } |
22 | |
23 | # test that path properly removes the base location |
24 | { |
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' ); |
30 | } |
31 | |
32 | # test that base + path is correct |
33 | { |
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' ); |
38 | } |
39 | |
de19de2e |
40 | # test base is correct for HTTPS URLs |
41 | SKIP: |
42 | { |
43 | if ( $ENV{CATALYST_SERVER} ) { |
44 | skip 'Using remote server', 5; |
45 | } |
46 | |
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' ); |
53 | } |
54 | |
c7ded7aa |
55 | # test that we can use semi-colons as separators |
56 | { |
57 | my $parameters = { |
58 | a => [ qw/1 2/ ], |
59 | b => 3, |
60 | }; |
61 | |
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' ); |
67 | } |
68 | |
69 | # test that query params are unescaped properly |
70 | { |
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' ); |
76 | } |
77 | |
78 | # test that uri_with adds params |
79 | { |
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' ); |
84 | } |
85 | |
86 | # test that uri_with adds params (and preserves) |
87 | { |
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' ); |
92 | } |
93 | |
94 | # test that uri_with replaces params (and preserves) |
95 | { |
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' ); |
100 | } |
101 | |
102 | # test that uri_with replaces params (and preserves) |
103 | { |
104 | ok( my $response = request('http://localhost/engine/request/uri/uri_with_object'), 'Request' ); |
105 | ok( $response->is_success, 'Response Successful 2xx' ); |
de19de2e |
106 | like( $response->header( 'X-Catalyst-Param-a' ), qr(https?://localhost[^/]*/), 'param "a" ok' ); |
c7ded7aa |
107 | } |
108 | |
109 | # test that uri_with is utf8 safe |
110 | { |
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' ); |
114 | } |
115 | |
116 | # test with undef -- no warnings should be thrown |
117 | { |
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' ); |
121 | } |
0ce22ad4 |
122 | |