Commit | Line | Data |
50cc3183 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
42da66a9 |
7 | use lib "$FindBin::Bin/../lib"; |
50cc3183 |
8 | |
9 | our $iters; |
10 | |
6b25e555 |
11 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
12 | |
e31b525c |
13 | use Test::More tests => 53 * $iters; |
50cc3183 |
14 | use Catalyst::Test 'TestApp'; |
15 | |
16 | if ( $ENV{CAT_BENCHMARK} ) { |
17 | require Benchmark; |
18 | Benchmark::timethis( $iters, \&run_tests ); |
19 | } |
20 | else { |
21 | for ( 1 .. $iters ) { |
22 | run_tests(); |
23 | } |
24 | } |
25 | |
26 | sub run_tests { |
27 | { |
28 | my @expected = qw[ |
29 | TestApp::Controller::Action::Forward->begin |
30 | TestApp::Controller::Action::Forward->one |
31 | TestApp::Controller::Action::Forward->two |
32 | TestApp::Controller::Action::Forward->three |
33 | TestApp::Controller::Action::Forward->four |
34 | TestApp::Controller::Action::Forward->five |
35 | TestApp::View::Dump::Request->process |
a0a66cb8 |
36 | TestApp::Controller::Root->end |
50cc3183 |
37 | ]; |
38 | |
39 | my $expected = join( ", ", @expected ); |
40 | |
41 | # Test forward to global private action |
42 | ok( my $response = request('http://localhost/action/forward/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/forward/global', 'Main Class Action' ); |
48 | |
49 | # Test forward to chain of actions. |
50 | ok( $response = request('http://localhost/action/forward/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/forward/one', 'Test Action' ); |
56 | is( |
57 | $response->header('X-Test-Class'), |
58 | 'TestApp::Controller::Action::Forward', |
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::Forward->begin |
73 | TestApp::Controller::Action::Forward->jojo |
74 | TestApp::Controller::Action::Forward->one |
75 | TestApp::Controller::Action::Forward->two |
76 | TestApp::Controller::Action::Forward->three |
77 | TestApp::Controller::Action::Forward->four |
78 | TestApp::Controller::Action::Forward->five |
79 | TestApp::View::Dump::Request->process |
80 | TestApp::Controller::Action::Forward->three |
81 | TestApp::Controller::Action::Forward->four |
82 | TestApp::Controller::Action::Forward->five |
83 | TestApp::View::Dump::Request->process |
a0a66cb8 |
84 | TestApp::Controller::Root->end |
50cc3183 |
85 | ]; |
86 | |
87 | my $expected = join( ", ", @expected ); |
88 | |
89 | ok( my $response = request('http://localhost/action/forward/jojo'), |
90 | 'Request' ); |
91 | ok( $response->is_success, 'Response Successful 2xx' ); |
92 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
93 | is( $response->header('X-Catalyst-Action'), |
94 | 'action/forward/jojo', 'Test Action' ); |
95 | is( |
96 | $response->header('X-Test-Class'), |
97 | 'TestApp::Controller::Action::Forward', |
98 | 'Test Class' |
99 | ); |
100 | is( $response->header('X-Catalyst-Executed'), |
101 | $expected, 'Executed actions' ); |
102 | like( |
103 | $response->content, |
104 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
105 | 'Content is a serialized Catalyst::Request' |
106 | ); |
107 | } |
108 | |
109 | { |
110 | ok( |
111 | my $response = |
112 | request('http://localhost/action/forward/with_args/old'), |
113 | 'Request with args' |
114 | ); |
115 | ok( $response->is_success, 'Response Successful 2xx' ); |
116 | is( $response->content, 'old' ); |
117 | } |
118 | |
119 | { |
120 | ok( |
121 | my $response = request( |
122 | 'http://localhost/action/forward/with_method_and_args/old'), |
123 | 'Request with args and method' |
124 | ); |
125 | ok( $response->is_success, 'Response Successful 2xx' ); |
126 | is( $response->content, 'old' ); |
127 | } |
128 | |
129 | # test forward with embedded args |
130 | { |
131 | ok( |
132 | my $response = |
133 | request('http://localhost/action/forward/args_embed_relative'), |
134 | 'Request' |
135 | ); |
136 | ok( $response->is_success, 'Response Successful 2xx' ); |
137 | is( $response->content, 'ok' ); |
138 | } |
139 | |
140 | { |
141 | ok( |
142 | my $response = |
143 | request('http://localhost/action/forward/args_embed_absolute'), |
144 | 'Request' |
145 | ); |
146 | ok( $response->is_success, 'Response Successful 2xx' ); |
147 | is( $response->content, 'ok' ); |
148 | } |
149 | { |
150 | my @expected = qw[ |
1b1636b5 |
151 | TestApp::Controller::Action::TestRelative->begin |
152 | TestApp::Controller::Action::TestRelative->relative |
50cc3183 |
153 | TestApp::Controller::Action::Forward->one |
154 | TestApp::Controller::Action::Forward->two |
155 | TestApp::Controller::Action::Forward->three |
156 | TestApp::Controller::Action::Forward->four |
157 | TestApp::Controller::Action::Forward->five |
158 | TestApp::View::Dump::Request->process |
a0a66cb8 |
159 | TestApp::Controller::Root->end |
50cc3183 |
160 | ]; |
161 | |
162 | my $expected = join( ", ", @expected ); |
163 | |
164 | # Test forward to chain of actions. |
165 | ok( my $response = request('http://localhost/action/relative/relative'), |
166 | 'Request' ); |
167 | ok( $response->is_success, 'Response Successful 2xx' ); |
168 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
169 | is( $response->header('X-Catalyst-Action'), |
170 | 'action/relative/relative', 'Test Action' ); |
171 | is( |
172 | $response->header('X-Test-Class'), |
1b1636b5 |
173 | 'TestApp::Controller::Action::TestRelative', |
50cc3183 |
174 | 'Test Class' |
175 | ); |
176 | is( $response->header('X-Catalyst-Executed'), |
177 | $expected, 'Executed actions' ); |
178 | like( |
179 | $response->content, |
180 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
181 | 'Content is a serialized Catalyst::Request' |
182 | ); |
183 | } |
184 | { |
185 | my @expected = qw[ |
1b1636b5 |
186 | TestApp::Controller::Action::TestRelative->begin |
187 | TestApp::Controller::Action::TestRelative->relative_two |
50cc3183 |
188 | TestApp::Controller::Action::Forward->one |
189 | TestApp::Controller::Action::Forward->two |
190 | TestApp::Controller::Action::Forward->three |
191 | TestApp::Controller::Action::Forward->four |
192 | TestApp::Controller::Action::Forward->five |
193 | TestApp::View::Dump::Request->process |
a0a66cb8 |
194 | TestApp::Controller::Root->end |
50cc3183 |
195 | ]; |
196 | |
197 | my $expected = join( ", ", @expected ); |
198 | |
199 | # Test forward to chain of actions. |
200 | ok( |
201 | my $response = |
202 | request('http://localhost/action/relative/relative_two'), |
203 | 'Request' |
204 | ); |
205 | ok( $response->is_success, 'Response Successful 2xx' ); |
206 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
207 | is( |
208 | $response->header('X-Catalyst-Action'), |
209 | 'action/relative/relative_two', |
210 | 'Test Action' |
211 | ); |
212 | is( |
213 | $response->header('X-Test-Class'), |
1b1636b5 |
214 | 'TestApp::Controller::Action::TestRelative', |
50cc3183 |
215 | 'Test Class' |
216 | ); |
217 | is( $response->header('X-Catalyst-Executed'), |
218 | $expected, 'Executed actions' ); |
219 | like( |
220 | $response->content, |
221 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
222 | 'Content is a serialized Catalyst::Request' |
223 | ); |
224 | } |
86d993ab |
225 | |
226 | # test class forwards |
227 | { |
228 | ok( |
229 | my $response = request( |
230 | 'http://localhost/action/forward/class_forward_test_action'), |
231 | 'Request' |
232 | ); |
233 | ok( $response->is_success, 'Response Successful 2xx' ); |
234 | is( $response->header('X-Class-Forward-Test-Method'), 1, |
235 | 'Test Method' ); |
236 | } |
237 | |
2f381252 |
238 | # test uri_for re r7385 |
239 | { |
240 | ok( my $response = request( |
241 | 'http://localhost/action/forward/forward_to_uri_check'), |
242 | 'forward_to_uri_check request'); |
243 | |
244 | ok( $response->is_success, 'forward_to_uri_check successful'); |
245 | is( $response->content, '/action/forward/foo/bar', |
246 | 'forward_to_uri_check correct namespace'); |
247 | } |
e31b525c |
248 | |
249 | # test forwarding to Catalyst::Action objects |
250 | { |
251 | ok( my $response = request( |
252 | 'http://localhost/action/forward/to_action_object'), |
253 | 'forward/to_action_object request'); |
254 | |
255 | ok( $response->is_success, 'forward/to_action_object successful'); |
256 | is( $response->content, 'mtfnpy', |
257 | 'forward/to_action_object forwards correctly'); |
258 | } |
50cc3183 |
259 | } |