052c9c1ba14ed70f859ff5a01ed887b2d08729dc
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_local.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 our $iters;
8
9 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
10
11 use Test::More tests => 34*$iters;
12 use Catalyst::Test 'TestApp';
13
14 if ( $ENV{CAT_BENCHMARK} ) {
15     require Benchmark;
16     Benchmark::timethis( $iters, \&run_tests );
17 }
18 else {
19     for ( 1 .. $iters ) {
20         run_tests();
21     }
22 }
23
24 sub run_tests {
25     {
26         ok( my $response = request('http://localhost/action/local/one'),
27             'Request' );
28         ok( $response->is_success, 'Response Successful 2xx' );
29         is( $response->content_type, 'text/plain', 'Response Content-Type' );
30         is( $response->header('X-Catalyst-Action'),
31             'action/local/one', 'Test Action' );
32         is(
33             $response->header('X-Test-Class'),
34             'TestApp::Controller::Action::Local',
35             'Test Class'
36         );
37         like(
38             $response->content,
39             qr/^bless\( .* 'Catalyst::Request' \)$/s,
40             'Content is a serialized Catalyst::Request'
41         );
42     }
43
44     {
45         ok( my $response = request('http://localhost/action/local/two/1/2'),
46             'Request' );
47         ok( $response->is_success, 'Response Successful 2xx' );
48         is( $response->content_type, 'text/plain', 'Response Content-Type' );
49         is( $response->header('X-Catalyst-Action'),
50             'action/local/two', 'Test Action' );
51         is(
52             $response->header('X-Test-Class'),
53             'TestApp::Controller::Action::Local',
54             'Test Class'
55         );
56         like(
57             $response->content,
58             qr/^bless\( .* 'Catalyst::Request' \)$/s,
59             'Content is a serialized Catalyst::Request'
60         );
61     }
62
63     {
64          ok( my $response = request('http://localhost/action/local/two'),
65                'Request' );
66          ok( !$response->is_success, 'Request with wrong number of args failed' );
67     }
68
69     {
70         ok( my $response = request('http://localhost/action/local/three'),
71             'Request' );
72         ok( $response->is_success, 'Response Successful 2xx' );
73         is( $response->content_type, 'text/plain', 'Response Content-Type' );
74         is( $response->header('X-Catalyst-Action'),
75             'action/local/three', 'Test Action' );
76         is(
77             $response->header('X-Test-Class'),
78             'TestApp::Controller::Action::Local',
79             'Test Class'
80         );
81         like(
82             $response->content,
83             qr/^bless\( .* 'Catalyst::Request' \)$/s,
84             'Content is a serialized Catalyst::Request'
85         );
86     }
87
88     {
89         ok(
90             my $response =
91               request('http://localhost/action/local/four/five/six'),
92             'Request'
93         );
94         ok( $response->is_success, 'Response Successful 2xx' );
95         is( $response->content_type, 'text/plain', 'Response Content-Type' );
96         is( $response->header('X-Catalyst-Action'),
97             'action/local/four/five/six', 'Test Action' );
98         is(
99             $response->header('X-Test-Class'),
100             'TestApp::Controller::Action::Local',
101             'Test Class'
102         );
103         like(
104             $response->content,
105             qr/^bless\( .* 'Catalyst::Request' \)$/s,
106             'Content is a serialized Catalyst::Request'
107         );
108     }
109
110     SKIP:
111     { 
112         if ( $ENV{CATALYST_SERVER} ) {
113             skip "tests for %2F on remote server", 6;
114         }
115         
116         ok(
117             my $response =
118               request('http://localhost/action/local/one/foo%2Fbar'),
119             'Request'
120         );
121         ok( $response->is_success, 'Response Successful 2xx' );
122         is( $response->content_type, 'text/plain', 'Response Content-Type' );
123         is( $response->header('X-Catalyst-Action'),
124             'action/local/one', 'Test Action' );
125         is(
126             $response->header('X-Test-Class'),
127             'TestApp::Controller::Action::Local',
128             'Test Class'
129         );
130         my $content = $response->content;
131         {
132             local $@;
133             my $request = eval $content;
134             if ($@) {
135                 fail("Content cannot be unserialized: $@ $content");
136             }
137             else {
138                 is_deeply $request->arguments, ['foo/bar'], "Parameters don't split on %2F";
139             }
140         }
141     }
142
143     {
144         ok( my $content = get('http://locahost/action/local/five/foo%2Fbar%3B'),
145             'request with URI-encoded arg');
146         # this is the CURRENT behavior
147         like( $content, qr{'foo/bar;'}, 'args for Local actions URI-decoded' );
148     }
149 }