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