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