5 use lib "$FindBin::Bin/../lib";
9 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
11 use Test::More tests => 60 * $iters;
12 use Catalyst::Test 'TestApp';
14 if ( $ENV{CAT_BENCHMARK} ) {
16 Benchmark::timethis( $iters, \&run_tests );
26 # Test visit to global private action
27 ok( my $response = request('http://localhost/action/visit/global'),
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' );
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
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
50 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
51 my $expected = join( ", ", @expected );
53 # Test visit to chain of actions.
54 ok( my $response = request('http://localhost/action/visit/one'),
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' );
61 $response->header('X-Test-Class'),
62 'TestApp::Controller::Action::Visit',
65 is( $response->header('X-Catalyst-Executed'),
66 $expected, 'Executed actions' );
69 qr/^bless\( .* 'Catalyst::Request' \)$/s,
70 'Content is a serialized Catalyst::Request'
75 TestApp::Controller::Action::Visit->visit_die
76 TestApp::Controller::Action::Visit->args
77 TestApp::Controller::Root->end
78 TestApp::Controller::Root->end
81 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
82 my $expected = join( ", ", @expected );
84 ok( my $response = request('http://localhost/action/visit/visit_die'),
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'
92 $response->header('X-Test-Class'),
93 'TestApp::Controller::Action::Visit',
96 is( $response->header('X-Catalyst-Executed'),
97 $expected, 'Executed actions' );
98 is( $response->content, "visit() doesn't die", "Visit does not die" );
102 my $response = request('http://localhost/action/visit/model'),
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?]
111 my $response = request('http://localhost/action/visit/view'),
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?]
121 request('http://localhost/action/visit/with_args/old'),
124 ok( $response->is_success, 'Response Successful 2xx' );
125 is( $response->content, 'old', 'visit() with args (old)' );
130 my $response = request(
131 'http://localhost/action/visit/with_method_and_args/new'),
132 'Request with args and method'
134 ok( $response->is_success, 'Response Successful 2xx' );
135 is( $response->content, 'new', 'visit() with args (new)' );
138 # test visit with embedded args
142 request('http://localhost/action/visit/args_embed_relative'),
145 ok( $response->is_success, 'Response Successful 2xx' );
146 is( $response->content, 'ok', 'visit() with args_embed_relative' );
152 request('http://localhost/action/visit/args_embed_absolute'),
155 ok( $response->is_success, 'Response Successful 2xx' );
156 is( $response->content, 'ok', 'visit() with args_embed_absolute' );
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
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
175 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
176 my $expected = join( ", ", @expected );
178 # Test visit to chain of actions.
179 ok( my $response = request('http://localhost/action/relative/relative_visit'),
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' );
186 $response->header('X-Test-Class'),
187 'TestApp::Controller::Action::Visit',
190 is( $response->header('X-Catalyst-Executed'),
191 $expected, 'Executed actions' );
194 qr/^bless\( .* 'Catalyst::Request' \)$/s,
195 'Content is a serialized Catalyst::Request'
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
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
215 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
216 my $expected = join( ", ", @expected );
218 # Test visit to chain of actions.
221 request('http://localhost/action/relative/relative_visit_two'),
224 ok( $response->is_success, 'Response Successful 2xx' );
225 is( $response->content_type, 'text/plain', 'Response Content-Type' );
227 $response->header('X-Catalyst-Action'),
228 'action/relative/relative_visit_two',
232 $response->header('X-Test-Class'),
233 'TestApp::Controller::Action::Visit',
236 is( $response->header('X-Catalyst-Executed'),
237 $expected, 'Executed actions' );
240 qr/^bless\( .* 'Catalyst::Request' \)$/s,
241 'Content is a serialized Catalyst::Request'
245 # test class visit -- MUST FAIL!
248 my $response = request(
249 'http://localhost/action/visit/class_visit_test_action'),
252 ok( !$response->is_success, 'Response Fails' );
253 is( $response->content,
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.},
255 "Cannot visit app namespace"
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
267 TestApp::Controller::Root->end
270 my $expected = join( ", ", @expected );
273 ok( my $response = request("http://localhost/action/visit/visit_chained/$i/becomescapture/arg1/arg2"),
274 "visit to chained + subcontroller endpoint for $i" );
275 is( $response->header('X-Catalyst-Executed'),
276 $expected, "Executed actions for $i" );
277 is( $response->content, "becomescapture; arg1, arg2",
278 "Content OK for $i" );