convert tabs to spaces and set unix line endings in t/*
[catagits/Catalyst-Runtime.git] / t / live_engine_request_uri.t
CommitLineData
c7ded7aa 1\feff#!perl
d0f0fcf6 2
c7ded7aa 3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
9use Test::More tests => 44;
10use Catalyst::Test 'TestApp';
11use Catalyst::Request;
12
13my $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
40# test that we can use semi-colons as separators
41{
42 my $parameters = {
43 a => [ qw/1 2/ ],
44 b => 3,
45 };
46
47 ok( my $response = request('http://localhost/engine/request/uri?a=1;a=2;b=3'), 'Request' );
48 ok( $response->is_success, 'Response Successful 2xx' );
49 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
50 is( $creq->{uri}->query, 'a=1;a=2;b=3', 'Query string ok' );
51 is_deeply( $creq->{parameters}, $parameters, 'Parameters ok' );
52}
53
54# test that query params are unescaped properly
55{
56 ok( my $response = request('http://localhost/engine/request/uri?text=Catalyst%20Rocks'), 'Request' );
57 ok( $response->is_success, 'Response Successful 2xx' );
58 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
59 is( $creq->{uri}->query, 'text=Catalyst%20Rocks', 'Query string ok' );
60 is( $creq->{parameters}->{text}, 'Catalyst Rocks', 'Unescaped param ok' );
61}
62
63# test that uri_with adds params
64{
65 ok( my $response = request('http://localhost/engine/request/uri/uri_with'), 'Request' );
66 ok( $response->is_success, 'Response Successful 2xx' );
67 ok( !defined $response->header( 'X-Catalyst-Param-a' ), 'param "a" ok' );
68 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
69}
70
71# test that uri_with adds params (and preserves)
72{
73 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1'), 'Request' );
74 ok( $response->is_success, 'Response Successful 2xx' );
75 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
76 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
77}
78
79# test that uri_with replaces params (and preserves)
80{
81 ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2'), 'Request' );
82 ok( $response->is_success, 'Response Successful 2xx' );
83 is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
84 is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
85}
86
87# test that uri_with replaces params (and preserves)
88{
89 ok( my $response = request('http://localhost/engine/request/uri/uri_with_object'), 'Request' );
90 ok( $response->is_success, 'Response Successful 2xx' );
91 like( $response->header( 'X-Catalyst-Param-a' ), qr(http://localhost[^/]*/), 'param "a" ok' );
92}
93
94# test that uri_with is utf8 safe
95{
96 ok( my $response = request("http://localhost/engine/request/uri/uri_with_utf8"), 'Request' );
97 ok( $response->is_success, 'Response Successful 2xx' );
98 like( $response->header( 'X-Catalyst-uri-with' ), qr/%E2%98%A0$/, 'uri_with ok' );
99}
100
101# test with undef -- no warnings should be thrown
102{
103 ok( my $response = request("http://localhost/engine/request/uri/uri_with_undef"), 'Request' );
104 ok( $response->is_success, 'Response Successful 2xx' );
105 is( $response->header( 'X-Catalyst-warnings' ), 0, 'no warnings emitted' );
106}