Commit | Line | Data |
ae0e35ee |
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 | |
62605319 |
11 | use Test::More tests => 60 * $iters; |
ae0e35ee |
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 | # Test visit to global private action |
27 | ok( my $response = request('http://localhost/action/visit/global'), |
28 | 'Request' ); |
29 | ok( $response->is_success, 'Response Successful 2xx' ); |
30 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
31 | is( $response->header('X-Catalyst-Action'), |
32 | 'action/visit/global', 'Main Class Action' ); |
33 | } |
34 | |
35 | { |
36 | my @expected = qw[ |
37 | TestApp::Controller::Action::Visit->one |
38 | TestApp::Controller::Action::Visit->two |
39 | TestApp::Controller::Action::Visit->three |
40 | TestApp::Controller::Action::Visit->four |
41 | TestApp::Controller::Action::Visit->five |
42 | TestApp::View::Dump::Request->process |
a0a66cb8 |
43 | TestApp::Controller::Root->end |
44 | TestApp::Controller::Root->end |
45 | TestApp::Controller::Root->end |
46 | TestApp::Controller::Root->end |
47 | TestApp::Controller::Root->end |
ae0e35ee |
48 | ]; |
49 | |
50 | @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected; |
51 | my $expected = join( ", ", @expected ); |
52 | |
53 | # Test visit to chain of actions. |
54 | ok( my $response = request('http://localhost/action/visit/one'), |
55 | 'Request' ); |
56 | ok( $response->is_success, 'Response Successful 2xx' ); |
57 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
58 | is( $response->header('X-Catalyst-Action'), |
59 | 'action/visit/one', 'Test Action' ); |
60 | is( |
61 | $response->header('X-Test-Class'), |
62 | 'TestApp::Controller::Action::Visit', |
63 | 'Test Class' |
64 | ); |
65 | is( $response->header('X-Catalyst-Executed'), |
66 | $expected, 'Executed actions' ); |
67 | like( |
68 | $response->content, |
69 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
70 | 'Content is a serialized Catalyst::Request' |
71 | ); |
72 | } |
73 | { |
74 | my @expected = qw[ |
75 | TestApp::Controller::Action::Visit->visit_die |
76 | TestApp::Controller::Action::Visit->args |
a0a66cb8 |
77 | TestApp::Controller::Root->end |
78 | TestApp::Controller::Root->end |
ae0e35ee |
79 | ]; |
80 | |
81 | @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected; |
82 | my $expected = join( ", ", @expected ); |
83 | |
84 | ok( my $response = request('http://localhost/action/visit/visit_die'), |
85 | 'Request' ); |
86 | ok( $response->is_success, 'Response Successful 2xx' ); |
87 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
88 | is( $response->header('X-Catalyst-Action'), |
89 | 'action/visit/visit_die', 'Test Action' |
90 | ); |
91 | is( |
92 | $response->header('X-Test-Class'), |
93 | 'TestApp::Controller::Action::Visit', |
94 | 'Test Class' |
95 | ); |
96 | is( $response->header('X-Catalyst-Executed'), |
97 | $expected, 'Executed actions' ); |
98 | is( $response->content, "visit() doesn't die", "Visit does not die" ); |
99 | } |
100 | { |
101 | ok( |
102 | my $response = request('http://localhost/action/visit/model'), |
103 | 'Request with args' |
104 | ); |
105 | is( $response->content, |
106 | q[FATAL ERROR: Couldn't visit("Model::Foo"): Action cannot _DISPATCH. Did you try to visit() a non-controller action?] |
107 | ); |
108 | } |
109 | { |
110 | ok( |
111 | my $response = request('http://localhost/action/visit/view'), |
112 | 'Request with args' |
113 | ); |
114 | is( $response->content, |
115 | q[FATAL ERROR: Couldn't visit("View::Dump"): Action cannot _DISPATCH. Did you try to visit() a non-controller action?] |
116 | ); |
117 | } |
118 | { |
119 | ok( |
120 | my $response = |
121 | request('http://localhost/action/visit/with_args/old'), |
122 | 'Request with args' |
123 | ); |
124 | ok( $response->is_success, 'Response Successful 2xx' ); |
125 | is( $response->content, 'old', 'visit() with args (old)' ); |
126 | } |
127 | |
128 | { |
129 | ok( |
130 | my $response = request( |
131 | 'http://localhost/action/visit/with_method_and_args/new'), |
132 | 'Request with args and method' |
133 | ); |
134 | ok( $response->is_success, 'Response Successful 2xx' ); |
135 | is( $response->content, 'new', 'visit() with args (new)' ); |
136 | } |
137 | |
138 | # test visit with embedded args |
139 | { |
140 | ok( |
141 | my $response = |
142 | request('http://localhost/action/visit/args_embed_relative'), |
143 | 'Request' |
144 | ); |
145 | ok( $response->is_success, 'Response Successful 2xx' ); |
146 | is( $response->content, 'ok', 'visit() with args_embed_relative' ); |
147 | } |
148 | |
149 | { |
150 | ok( |
151 | my $response = |
152 | request('http://localhost/action/visit/args_embed_absolute'), |
153 | 'Request' |
154 | ); |
155 | ok( $response->is_success, 'Response Successful 2xx' ); |
156 | is( $response->content, 'ok', 'visit() with args_embed_absolute' ); |
157 | } |
158 | { |
159 | my @expected = qw[ |
160 | TestApp::Controller::Action::TestRelative->relative_visit |
161 | TestApp::Controller::Action::Visit->one |
162 | TestApp::Controller::Action::Visit->two |
163 | TestApp::Controller::Action::Visit->three |
164 | TestApp::Controller::Action::Visit->four |
165 | TestApp::Controller::Action::Visit->five |
166 | TestApp::View::Dump::Request->process |
a0a66cb8 |
167 | TestApp::Controller::Root->end |
168 | TestApp::Controller::Root->end |
169 | TestApp::Controller::Root->end |
170 | TestApp::Controller::Root->end |
171 | TestApp::Controller::Root->end |
172 | TestApp::Controller::Root->end |
ae0e35ee |
173 | ]; |
174 | |
175 | @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected; |
176 | my $expected = join( ", ", @expected ); |
177 | |
178 | # Test visit to chain of actions. |
179 | ok( my $response = request('http://localhost/action/relative/relative_visit'), |
180 | 'Request' ); |
181 | ok( $response->is_success, 'Response Successful 2xx' ); |
182 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
183 | is( $response->header('X-Catalyst-Action'), |
184 | 'action/relative/relative_visit', 'Test Action' ); |
185 | is( |
186 | $response->header('X-Test-Class'), |
187 | 'TestApp::Controller::Action::Visit', |
188 | 'Test Class' |
189 | ); |
190 | is( $response->header('X-Catalyst-Executed'), |
191 | $expected, 'Executed actions' ); |
192 | like( |
193 | $response->content, |
194 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
195 | 'Content is a serialized Catalyst::Request' |
196 | ); |
197 | } |
198 | { |
199 | my @expected = qw[ |
200 | TestApp::Controller::Action::TestRelative->relative_visit_two |
201 | TestApp::Controller::Action::Visit->one |
202 | TestApp::Controller::Action::Visit->two |
203 | TestApp::Controller::Action::Visit->three |
204 | TestApp::Controller::Action::Visit->four |
205 | TestApp::Controller::Action::Visit->five |
206 | TestApp::View::Dump::Request->process |
a0a66cb8 |
207 | TestApp::Controller::Root->end |
208 | TestApp::Controller::Root->end |
209 | TestApp::Controller::Root->end |
210 | TestApp::Controller::Root->end |
211 | TestApp::Controller::Root->end |
212 | TestApp::Controller::Root->end |
ae0e35ee |
213 | ]; |
214 | |
215 | @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected; |
216 | my $expected = join( ", ", @expected ); |
217 | |
218 | # Test visit to chain of actions. |
219 | ok( |
220 | my $response = |
221 | request('http://localhost/action/relative/relative_visit_two'), |
222 | 'Request' |
223 | ); |
224 | ok( $response->is_success, 'Response Successful 2xx' ); |
225 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
226 | is( |
227 | $response->header('X-Catalyst-Action'), |
228 | 'action/relative/relative_visit_two', |
229 | 'Test Action' |
230 | ); |
231 | is( |
232 | $response->header('X-Test-Class'), |
233 | 'TestApp::Controller::Action::Visit', |
234 | 'Test Class' |
235 | ); |
236 | is( $response->header('X-Catalyst-Executed'), |
237 | $expected, 'Executed actions' ); |
238 | like( |
239 | $response->content, |
240 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
241 | 'Content is a serialized Catalyst::Request' |
242 | ); |
243 | } |
244 | |
245 | # test class visit -- MUST FAIL! |
246 | { |
247 | ok( |
248 | my $response = request( |
249 | 'http://localhost/action/visit/class_visit_test_action'), |
250 | 'Request' |
251 | ); |
252 | ok( !$response->is_success, 'Response Fails' ); |
253 | is( $response->content, |
382d317c |
254 | q{FATAL ERROR: Couldn't visit("TestApp"): Action has no namespace: cannot visit() to a plain method or component, must be an :Action of some sort.}, |
ae0e35ee |
255 | "Cannot visit app namespace" |
256 | ); |
257 | } |
258 | |
259 | { |
260 | my @expected = qw[ |
261 | TestApp::Controller::Action::Visit->begin |
262 | TestApp::Controller::Action::Visit->visit_chained |
263 | TestApp::Controller::Action::Chained->begin |
264 | TestApp::Controller::Action::Chained->foo |
265 | TestApp::Controller::Action::Chained::Foo->spoon |
266 | TestApp::Controller::Action::Chained->end |
a0a66cb8 |
267 | TestApp::Controller::Root->end |
ae0e35ee |
268 | ]; |
269 | |
270 | my $expected = join( ", ", @expected ); |
271 | |
62605319 |
272 | for my $i ( 1..3 ) { |
b456f8f3 |
273 | ok( my $response = request("http://localhost/action/visit/visit_chained/$i/becomescapture/arg1/arg2"), |
62605319 |
274 | "visit to chained + subcontroller endpoint for $i" ); |
275 | is( $response->header('X-Catalyst-Executed'), |
276 | $expected, "Executed actions for $i" ); |
e1e81442 |
277 | is( $response->content, "becomescapture; arg1, arg2", |
b456f8f3 |
278 | "Content OK for $i" ); |
62605319 |
279 | } |
ae0e35ee |
280 | } |
281 | |
282 | } |
283 | |
284 | |
285 | |
286 | sub _begin { |
287 | local $_ = shift; |
288 | s/->(.*)$/->begin/; |
289 | return $_; |
290 | } |
291 | |