7 use lib "$FindBin::Bin/../lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
13 use Test::More tests => 60 * $iters;
14 use Catalyst::Test 'TestApp';
16 if ( $ENV{CAT_BENCHMARK} ) {
18 Benchmark::timethis( $iters, \&run_tests );
28 # Test visit to global private action
29 ok( my $response = request('http://localhost/action/visit/global'),
31 ok( $response->is_success, 'Response Successful 2xx' );
32 is( $response->content_type, 'text/plain', 'Response Content-Type' );
33 is( $response->header('X-Catalyst-Action'),
34 'action/visit/global', 'Main Class Action' );
39 TestApp::Controller::Action::Visit->one
40 TestApp::Controller::Action::Visit->two
41 TestApp::Controller::Action::Visit->three
42 TestApp::Controller::Action::Visit->four
43 TestApp::Controller::Action::Visit->five
44 TestApp::View::Dump::Request->process
45 TestApp::Controller::Root->end
46 TestApp::Controller::Root->end
47 TestApp::Controller::Root->end
48 TestApp::Controller::Root->end
49 TestApp::Controller::Root->end
52 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
53 my $expected = join( ", ", @expected );
55 # Test visit to chain of actions.
56 ok( my $response = request('http://localhost/action/visit/one'),
58 ok( $response->is_success, 'Response Successful 2xx' );
59 is( $response->content_type, 'text/plain', 'Response Content-Type' );
60 is( $response->header('X-Catalyst-Action'),
61 'action/visit/one', 'Test Action' );
63 $response->header('X-Test-Class'),
64 'TestApp::Controller::Action::Visit',
67 is( $response->header('X-Catalyst-Executed'),
68 $expected, 'Executed actions' );
71 qr/^bless\( .* 'Catalyst::Request' \)$/s,
72 'Content is a serialized Catalyst::Request'
77 TestApp::Controller::Action::Visit->visit_die
78 TestApp::Controller::Action::Visit->args
79 TestApp::Controller::Root->end
80 TestApp::Controller::Root->end
83 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
84 my $expected = join( ", ", @expected );
86 ok( my $response = request('http://localhost/action/visit/visit_die'),
88 ok( $response->is_success, 'Response Successful 2xx' );
89 is( $response->content_type, 'text/plain', 'Response Content-Type' );
90 is( $response->header('X-Catalyst-Action'),
91 'action/visit/visit_die', 'Test Action'
94 $response->header('X-Test-Class'),
95 'TestApp::Controller::Action::Visit',
98 is( $response->header('X-Catalyst-Executed'),
99 $expected, 'Executed actions' );
100 is( $response->content, "visit() doesn't die", "Visit does not die" );
104 my $response = request('http://localhost/action/visit/model'),
107 is( $response->content,
108 q[FATAL ERROR: Couldn't visit("Model::Foo"): Action cannot _DISPATCH. Did you try to visit() a non-controller action?]
113 my $response = request('http://localhost/action/visit/view'),
116 is( $response->content,
117 q[FATAL ERROR: Couldn't visit("View::Dump"): Action cannot _DISPATCH. Did you try to visit() a non-controller action?]
123 request('http://localhost/action/visit/with_args/old'),
126 ok( $response->is_success, 'Response Successful 2xx' );
127 is( $response->content, 'old', 'visit() with args (old)' );
132 my $response = request(
133 'http://localhost/action/visit/with_method_and_args/new'),
134 'Request with args and method'
136 ok( $response->is_success, 'Response Successful 2xx' );
137 is( $response->content, 'new', 'visit() with args (new)' );
140 # test visit with embedded args
144 request('http://localhost/action/visit/args_embed_relative'),
147 ok( $response->is_success, 'Response Successful 2xx' );
148 is( $response->content, 'ok', 'visit() with args_embed_relative' );
154 request('http://localhost/action/visit/args_embed_absolute'),
157 ok( $response->is_success, 'Response Successful 2xx' );
158 is( $response->content, 'ok', 'visit() with args_embed_absolute' );
162 TestApp::Controller::Action::TestRelative->relative_visit
163 TestApp::Controller::Action::Visit->one
164 TestApp::Controller::Action::Visit->two
165 TestApp::Controller::Action::Visit->three
166 TestApp::Controller::Action::Visit->four
167 TestApp::Controller::Action::Visit->five
168 TestApp::View::Dump::Request->process
169 TestApp::Controller::Root->end
170 TestApp::Controller::Root->end
171 TestApp::Controller::Root->end
172 TestApp::Controller::Root->end
173 TestApp::Controller::Root->end
174 TestApp::Controller::Root->end
177 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
178 my $expected = join( ", ", @expected );
180 # Test visit to chain of actions.
181 ok( my $response = request('http://localhost/action/relative/relative_visit'),
183 ok( $response->is_success, 'Response Successful 2xx' );
184 is( $response->content_type, 'text/plain', 'Response Content-Type' );
185 is( $response->header('X-Catalyst-Action'),
186 'action/relative/relative_visit', 'Test Action' );
188 $response->header('X-Test-Class'),
189 'TestApp::Controller::Action::Visit',
192 is( $response->header('X-Catalyst-Executed'),
193 $expected, 'Executed actions' );
196 qr/^bless\( .* 'Catalyst::Request' \)$/s,
197 'Content is a serialized Catalyst::Request'
202 TestApp::Controller::Action::TestRelative->relative_visit_two
203 TestApp::Controller::Action::Visit->one
204 TestApp::Controller::Action::Visit->two
205 TestApp::Controller::Action::Visit->three
206 TestApp::Controller::Action::Visit->four
207 TestApp::Controller::Action::Visit->five
208 TestApp::View::Dump::Request->process
209 TestApp::Controller::Root->end
210 TestApp::Controller::Root->end
211 TestApp::Controller::Root->end
212 TestApp::Controller::Root->end
213 TestApp::Controller::Root->end
214 TestApp::Controller::Root->end
217 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
218 my $expected = join( ", ", @expected );
220 # Test visit to chain of actions.
223 request('http://localhost/action/relative/relative_visit_two'),
226 ok( $response->is_success, 'Response Successful 2xx' );
227 is( $response->content_type, 'text/plain', 'Response Content-Type' );
229 $response->header('X-Catalyst-Action'),
230 'action/relative/relative_visit_two',
234 $response->header('X-Test-Class'),
235 'TestApp::Controller::Action::Visit',
238 is( $response->header('X-Catalyst-Executed'),
239 $expected, 'Executed actions' );
242 qr/^bless\( .* 'Catalyst::Request' \)$/s,
243 'Content is a serialized Catalyst::Request'
247 # test class visit -- MUST FAIL!
250 my $response = request(
251 'http://localhost/action/visit/class_visit_test_action'),
254 ok( !$response->is_success, 'Response Fails' );
255 is( $response->content,
256 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.},
257 "Cannot visit app namespace"
263 TestApp::Controller::Action::Visit->begin
264 TestApp::Controller::Action::Visit->visit_chained
265 TestApp::Controller::Action::Chained->begin
266 TestApp::Controller::Action::Chained->foo
267 TestApp::Controller::Action::Chained::Foo->spoon
268 TestApp::Controller::Action::Chained->end
269 TestApp::Controller::Root->end
272 my $expected = join( ", ", @expected );
275 ok( my $response = request("http://localhost/action/visit/visit_chained/$i/becomescapture/arg1/arg2"),
276 "visit to chained + subcontroller endpoint for $i" );
277 is( $response->header('X-Catalyst-Executed'),
278 $expected, "Executed actions for $i" );
279 is( $response->content, "becomescapture; arg1, arg2",
280 "Content OK for $i" );