7 use lib "$FindBin::Bin/../lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
13 use Test::More tests => 54 * $iters;
15 use Catalyst::Test 'TestApp';
17 if ( $ENV{CAT_BENCHMARK} ) {
19 Benchmark::timethis( $iters, \&run_tests );
29 # Test go to global private action
30 ok( my $response = request('http://localhost/action/go/global'),
32 ok( $response->is_success, 'Response Successful 2xx' );
33 is( $response->content_type, 'text/plain', 'Response Content-Type' );
34 is( $response->header('X-Catalyst-Action'),
35 'action/go/global', 'Main Class Action' );
40 TestApp::Controller::Action::Go->one
41 TestApp::Controller::Action::Go->two
42 TestApp::Controller::Action::Go->three
43 TestApp::Controller::Action::Go->four
44 TestApp::Controller::Action::Go->five
45 TestApp::View::Dump::Request->process
49 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
50 my $expected = join( ", ", @expected );
52 # Test go to chain of actions.
53 ok( my $response = request('http://localhost/action/go/one'),
55 ok( $response->is_success, 'Response Successful 2xx' );
56 is( $response->content_type, 'text/plain', 'Response Content-Type' );
57 is( $response->header('X-Catalyst-Action'),
58 'action/go/one', 'Test Action' );
60 $response->header('X-Test-Class'),
61 'TestApp::Controller::Action::Go',
64 is( $response->header('X-Catalyst-Executed'),
65 $expected, 'Executed actions' );
68 qr/^bless\( .* 'Catalyst::Request' \)$/s,
69 'Content is a serialized Catalyst::Request'
75 TestApp::Controller::Action::Go->go_die
76 TestApp::Controller::Action::Go->args
80 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
81 my $expected = join( ", ", @expected );
83 ok( my $response = request('http://localhost/action/go/go_die'),
85 ok( $response->is_success, 'Response Successful 2xx' );
86 is( $response->content_type, 'text/plain', 'Response Content-Type' );
87 is( $response->header('X-Catalyst-Action'),
88 'action/go/go_die', 'Test Action'
91 $response->header('X-Test-Class'),
92 'TestApp::Controller::Action::Go',
95 is( $response->header('X-Catalyst-Executed'),
96 $expected, 'Executed actions' );
97 is( $response->content, $Catalyst::GO, "Go died as expected" );
101 my $response = request('http://localhost/action/go/model'),
104 is( $response->content,
105 q[FATAL ERROR: Couldn't go("Model::Foo"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
106 q[go('Model::...') test]
111 my $response = request('http://localhost/action/go/view'),
114 is( $response->content,
115 q[FATAL ERROR: Couldn't go("View::Dump"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
116 q[go('View::...') test]
122 request('http://localhost/action/go/with_args/old'),
125 ok( $response->is_success, 'Response Successful 2xx' );
126 is( $response->content, 'old', 'go() with args (old)' );
131 my $response = request(
132 'http://localhost/action/go/with_method_and_args/new'),
133 'Request with args and method'
135 ok( $response->is_success, 'Response Successful 2xx' );
136 is( $response->content, 'new', 'go() with args (new)' );
139 # test go with embedded args
143 request('http://localhost/action/go/args_embed_relative'),
146 ok( $response->is_success, 'Response Successful 2xx' );
147 is( $response->content, 'ok', 'go() with args_embed_relative' );
153 request('http://localhost/action/go/args_embed_absolute'),
156 ok( $response->is_success, 'Response Successful 2xx' );
157 is( $response->content, 'ok', 'go() with args_embed_absolute' );
161 TestApp::Controller::Action::TestRelative->relative_go
162 TestApp::Controller::Action::Go->one
163 TestApp::Controller::Action::Go->two
164 TestApp::Controller::Action::Go->three
165 TestApp::Controller::Action::Go->four
166 TestApp::Controller::Action::Go->five
167 TestApp::View::Dump::Request->process
171 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
172 my $expected = join( ", ", @expected );
174 # Test go to chain of actions.
175 ok( my $response = request('http://localhost/action/relative/relative_go'),
177 ok( $response->is_success, 'Response Successful 2xx' );
178 is( $response->content_type, 'text/plain', 'Response Content-Type' );
179 is( $response->header('X-Catalyst-Action'),
180 'action/relative/relative_go', 'Test Action' );
182 $response->header('X-Test-Class'),
183 'TestApp::Controller::Action::Go',
186 is( $response->header('X-Catalyst-Executed'),
187 $expected, 'Executed actions' );
190 qr/^bless\( .* 'Catalyst::Request' \)$/s,
191 'Content is a serialized Catalyst::Request'
196 TestApp::Controller::Action::TestRelative->relative_go_two
197 TestApp::Controller::Action::Go->one
198 TestApp::Controller::Action::Go->two
199 TestApp::Controller::Action::Go->three
200 TestApp::Controller::Action::Go->four
201 TestApp::Controller::Action::Go->five
202 TestApp::View::Dump::Request->process
206 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
207 my $expected = join( ", ", @expected );
209 # Test go to chain of actions.
212 request('http://localhost/action/relative/relative_go_two'),
215 ok( $response->is_success, 'Response Successful 2xx' );
216 is( $response->content_type, 'text/plain', 'Response Content-Type' );
218 $response->header('X-Catalyst-Action'),
219 'action/relative/relative_go_two',
223 $response->header('X-Test-Class'),
224 'TestApp::Controller::Action::Go',
227 is( $response->header('X-Catalyst-Executed'),
228 $expected, 'Executed actions' );
231 qr/^bless\( .* 'Catalyst::Request' \)$/s,
232 'Content is a serialized Catalyst::Request'
236 # test class go -- MUST FAIL!
239 my $response = request(
240 'http://localhost/action/go/class_go_test_action'),
243 ok( !$response->is_success, 'Response Fails' );
244 is( $response->content,
245 q(FATAL ERROR: Couldn't go("TestApp"): Action has no namespace: cannot go() to a plain method or component, must be an :Action of some sort.),
252 TestApp::Controller::Action::Go->begin
253 TestApp::Controller::Action::Go->go_chained
254 TestApp::Controller::Action::Chained->begin
255 TestApp::Controller::Action::Chained->foo
256 TestApp::Controller::Action::Chained::Foo->spoon
257 TestApp::Controller::Action::Chained->end
260 my $expected = join( ", ", @expected );
262 ok( my $response = request('http://localhost/action/go/go_chained'), 'go to chained + subcontroller endpoint' );
263 is( $response->header('X-Catalyst-Executed'),
264 $expected, 'Executed actions' );
265 is( $response->content, 'arg1, arg2; captureme', 'Content OK' );