Improve docs for uri_for
[catagits/Catalyst-Runtime.git] / t / live_component_controller_action_go.t
CommitLineData
9bfaf006 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
9our $iters;
10
11BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
12
be7ce1dc 13use Test::More tests => 50 * $iters;
9bfaf006 14use Catalyst::Test 'TestApp';
15
16if ( $ENV{CAT_BENCHMARK} ) {
17 require Benchmark;
18 Benchmark::timethis( $iters, \&run_tests );
19}
20else {
21 for ( 1 .. $iters ) {
22 run_tests();
23 }
24}
25
26sub run_tests {
27 {
2034b8c3 28 # Test go to global private action
29 ok( my $response = request('http://localhost/action/go/global'),
30 'Request' );
31 ok( $response->is_success, 'Response Successful 2xx' );
32 is( $response->content_type, 'text/plain', 'Response Content-Type' );
33 is( $response->header('X-Catalyst-Action'),
34 'action/go/global', 'Main Class Action' );
35 }
36
37 {
9bfaf006 38 my @expected = qw[
39 TestApp::Controller::Action::Go->one
40 TestApp::Controller::Action::Go->two
41 TestApp::Controller::Action::Go->three
42 TestApp::Controller::Action::Go->four
43 TestApp::Controller::Action::Go->five
44 TestApp::View::Dump::Request->process
45 TestApp->end
46 ];
47
48 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
49 my $expected = join( ", ", @expected );
50
9bfaf006 51 # Test go to chain of actions.
2034b8c3 52 ok( my $response = request('http://localhost/action/go/one'),
9bfaf006 53 'Request' );
54 ok( $response->is_success, 'Response Successful 2xx' );
55 is( $response->content_type, 'text/plain', 'Response Content-Type' );
56 is( $response->header('X-Catalyst-Action'),
57 'action/go/one', 'Test Action' );
58 is(
59 $response->header('X-Test-Class'),
60 'TestApp::Controller::Action::Go',
61 'Test Class'
62 );
63 is( $response->header('X-Catalyst-Executed'),
64 $expected, 'Executed actions' );
65 like(
66 $response->content,
67 qr/^bless\( .* 'Catalyst::Request' \)$/s,
68 'Content is a serialized Catalyst::Request'
69 );
70 }
71
72 {
73 my @expected = qw[
74 TestApp::Controller::Action::Go->go_die
75 TestApp::Controller::Action::Go->args
76 TestApp->end
77 ];
78
79 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
80 my $expected = join( ", ", @expected );
81
82 ok( my $response = request('http://localhost/action/go/go_die'),
83 'Request' );
84 ok( $response->is_success, 'Response Successful 2xx' );
85 is( $response->content_type, 'text/plain', 'Response Content-Type' );
86 is( $response->header('X-Catalyst-Action'),
87 'action/go/go_die', 'Test Action'
88 );
89 is(
90 $response->header('X-Test-Class'),
91 'TestApp::Controller::Action::Go',
92 'Test Class'
93 );
94 is( $response->header('X-Catalyst-Executed'),
95 $expected, 'Executed actions' );
96 is( $response->content, $Catalyst::GO, "Go died as expected" );
97 }
98
99 {
100 ok(
101 my $response =
102 request('http://localhost/action/go/with_args/old'),
103 'Request with args'
104 );
105 ok( $response->is_success, 'Response Successful 2xx' );
106 is( $response->content, 'old' );
107 }
108
109 {
110 ok(
111 my $response = request(
112 'http://localhost/action/go/with_method_and_args/new'),
113 'Request with args and method'
114 );
115 ok( $response->is_success, 'Response Successful 2xx' );
116 is( $response->content, 'new' );
117 }
118
119 # test go with embedded args
120 {
121 ok(
122 my $response =
123 request('http://localhost/action/go/args_embed_relative'),
124 'Request'
125 );
126 ok( $response->is_success, 'Response Successful 2xx' );
127 is( $response->content, 'ok' );
128 }
129
130 {
131 ok(
132 my $response =
133 request('http://localhost/action/go/args_embed_absolute'),
134 'Request'
135 );
136 ok( $response->is_success, 'Response Successful 2xx' );
137 is( $response->content, 'ok' );
138 }
139 {
140 my @expected = qw[
141 TestApp::Controller::Action::TestRelative->relative_go
142 TestApp::Controller::Action::Go->one
143 TestApp::Controller::Action::Go->two
144 TestApp::Controller::Action::Go->three
145 TestApp::Controller::Action::Go->four
146 TestApp::Controller::Action::Go->five
147 TestApp::View::Dump::Request->process
148 TestApp->end
149 ];
150
151 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
152 my $expected = join( ", ", @expected );
153
154 # Test go to chain of actions.
155 ok( my $response = request('http://localhost/action/relative/relative_go'),
156 'Request' );
157 ok( $response->is_success, 'Response Successful 2xx' );
158 is( $response->content_type, 'text/plain', 'Response Content-Type' );
159 is( $response->header('X-Catalyst-Action'),
160 'action/relative/relative_go', 'Test Action' );
161 is(
162 $response->header('X-Test-Class'),
163 'TestApp::Controller::Action::Go',
164 'Test Class'
165 );
166 is( $response->header('X-Catalyst-Executed'),
167 $expected, 'Executed actions' );
168 like(
169 $response->content,
170 qr/^bless\( .* 'Catalyst::Request' \)$/s,
171 'Content is a serialized Catalyst::Request'
172 );
173 }
174 {
175 my @expected = qw[
176 TestApp::Controller::Action::TestRelative->relative_go_two
177 TestApp::Controller::Action::Go->one
178 TestApp::Controller::Action::Go->two
179 TestApp::Controller::Action::Go->three
180 TestApp::Controller::Action::Go->four
181 TestApp::Controller::Action::Go->five
182 TestApp::View::Dump::Request->process
183 TestApp->end
184 ];
185
186 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
187 my $expected = join( ", ", @expected );
188
189 # Test go to chain of actions.
190 ok(
191 my $response =
192 request('http://localhost/action/relative/relative_go_two'),
193 'Request'
194 );
195 ok( $response->is_success, 'Response Successful 2xx' );
196 is( $response->content_type, 'text/plain', 'Response Content-Type' );
197 is(
198 $response->header('X-Catalyst-Action'),
199 'action/relative/relative_go_two',
200 'Test Action'
201 );
202 is(
203 $response->header('X-Test-Class'),
204 'TestApp::Controller::Action::Go',
205 'Test Class'
206 );
207 is( $response->header('X-Catalyst-Executed'),
208 $expected, 'Executed actions' );
209 like(
210 $response->content,
211 qr/^bless\( .* 'Catalyst::Request' \)$/s,
212 'Content is a serialized Catalyst::Request'
213 );
214 }
215
2034b8c3 216 # test class go -- MUST FAIL!
9bfaf006 217 {
218 ok(
219 my $response = request(
220 'http://localhost/action/go/class_go_test_action'),
221 'Request'
222 );
2034b8c3 223 ok( !$response->is_success, 'Response Fails' );
224 is( $response->content, q(FATAL ERROR: Couldn't go to command "TestApp": Invalid action or component.), 'Error message' );
9bfaf006 225 }
226
be7ce1dc 227 {
228 my @expected = qw[
229 TestApp::Controller::Action::Go->begin
230 TestApp::Controller::Action::Go->go_chained
231 TestApp::Controller::Action::Chained->begin
232 TestApp::Controller::Action::Chained->foo
233 TestApp::Controller::Action::Chained::Foo->spoon
234 TestApp::Controller::Action::Chained->end
235 ];
236
237 my $expected = join( ", ", @expected );
238
239 ok( my $response = request('http://localhost/action/go/go_chained'), 'go to chained + subcontroller endpoint' );
240 is( $response->header('X-Catalyst-Executed'),
241 $expected, 'Executed actions' );
242 is( $response->content, '; 1', 'Content OK' );
243 }
244
9bfaf006 245}
246
be7ce1dc 247
248
9bfaf006 249sub _begin {
250 local $_ = shift;
251 s/->(.*)$/->begin/;
252 return $_;
253}
254