7 use lib "$FindBin::Bin/../lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
13 use Test::More tests => 54 * $iters;
14 use Catalyst::Test 'TestApp';
16 if ( $ENV{CAT_BENCHMARK} ) {
18 Benchmark::timethis( $iters, \&run_tests );
28 # Test go to global private action
29 ok( my $response = request('http://localhost/action/go/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/go/global', 'Main Class Action' );
39 TestApp::Controller::Action::Go->one
40 TestApp::Controller::Action::Go->two
41 TestApp::Controller::Action::Go->three
42 TestApp::Controller::Action::Go->four
43 TestApp::Controller::Action::Go->five
44 TestApp::View::Dump::Request->process
48 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
49 my $expected = join( ", ", @expected );
51 # Test go to chain of actions.
52 ok( my $response = request('http://localhost/action/go/one'),
54 ok( $response->is_success, 'Response Successful 2xx' );
55 is( $response->content_type, 'text/plain', 'Response Content-Type' );
56 is( $response->header('X-Catalyst-Action'),
57 'action/go/one', 'Test Action' );
59 $response->header('X-Test-Class'),
60 'TestApp::Controller::Action::Go',
63 is( $response->header('X-Catalyst-Executed'),
64 $expected, 'Executed actions' );
67 qr/^bless\( .* 'Catalyst::Request' \)$/s,
68 'Content is a serialized Catalyst::Request'
74 TestApp::Controller::Action::Go->go_die
75 TestApp::Controller::Action::Go->args
79 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
80 my $expected = join( ", ", @expected );
82 ok( my $response = request('http://localhost/action/go/go_die'),
84 ok( $response->is_success, 'Response Successful 2xx' );
85 is( $response->content_type, 'text/plain', 'Response Content-Type' );
86 is( $response->header('X-Catalyst-Action'),
87 'action/go/go_die', 'Test Action'
90 $response->header('X-Test-Class'),
91 'TestApp::Controller::Action::Go',
94 is( $response->header('X-Catalyst-Executed'),
95 $expected, 'Executed actions' );
96 is( $response->content, $Catalyst::GO, "Go died as expected" );
100 my $response = request('http://localhost/action/go/model'),
103 is( $response->content,
104 q[FATAL ERROR: Couldn't go("Model::Foo"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
105 q[go('Model::...') test]
110 my $response = request('http://localhost/action/go/view'),
113 is( $response->content,
114 q[FATAL ERROR: Couldn't go("View::Dump"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
115 q[go('View::...') test]
121 request('http://localhost/action/go/with_args/old'),
124 ok( $response->is_success, 'Response Successful 2xx' );
125 is( $response->content, 'old', 'go() with args (old)' );
130 my $response = request(
131 'http://localhost/action/go/with_method_and_args/new'),
132 'Request with args and method'
134 ok( $response->is_success, 'Response Successful 2xx' );
135 is( $response->content, 'new', 'go() with args (new)' );
138 # test go with embedded args
142 request('http://localhost/action/go/args_embed_relative'),
145 ok( $response->is_success, 'Response Successful 2xx' );
146 is( $response->content, 'ok', 'go() with args_embed_relative' );
152 request('http://localhost/action/go/args_embed_absolute'),
155 ok( $response->is_success, 'Response Successful 2xx' );
156 is( $response->content, 'ok', 'go() with args_embed_absolute' );
160 TestApp::Controller::Action::TestRelative->relative_go
161 TestApp::Controller::Action::Go->one
162 TestApp::Controller::Action::Go->two
163 TestApp::Controller::Action::Go->three
164 TestApp::Controller::Action::Go->four
165 TestApp::Controller::Action::Go->five
166 TestApp::View::Dump::Request->process
170 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
171 my $expected = join( ", ", @expected );
173 # Test go to chain of actions.
174 ok( my $response = request('http://localhost/action/relative/relative_go'),
176 ok( $response->is_success, 'Response Successful 2xx' );
177 is( $response->content_type, 'text/plain', 'Response Content-Type' );
178 is( $response->header('X-Catalyst-Action'),
179 'action/relative/relative_go', 'Test Action' );
181 $response->header('X-Test-Class'),
182 'TestApp::Controller::Action::Go',
185 is( $response->header('X-Catalyst-Executed'),
186 $expected, 'Executed actions' );
189 qr/^bless\( .* 'Catalyst::Request' \)$/s,
190 'Content is a serialized Catalyst::Request'
195 TestApp::Controller::Action::TestRelative->relative_go_two
196 TestApp::Controller::Action::Go->one
197 TestApp::Controller::Action::Go->two
198 TestApp::Controller::Action::Go->three
199 TestApp::Controller::Action::Go->four
200 TestApp::Controller::Action::Go->five
201 TestApp::View::Dump::Request->process
205 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
206 my $expected = join( ", ", @expected );
208 # Test go to chain of actions.
211 request('http://localhost/action/relative/relative_go_two'),
214 ok( $response->is_success, 'Response Successful 2xx' );
215 is( $response->content_type, 'text/plain', 'Response Content-Type' );
217 $response->header('X-Catalyst-Action'),
218 'action/relative/relative_go_two',
222 $response->header('X-Test-Class'),
223 'TestApp::Controller::Action::Go',
226 is( $response->header('X-Catalyst-Executed'),
227 $expected, 'Executed actions' );
230 qr/^bless\( .* 'Catalyst::Request' \)$/s,
231 'Content is a serialized Catalyst::Request'
235 # test class go -- MUST FAIL!
238 my $response = request(
239 'http://localhost/action/go/class_go_test_action'),
242 ok( !$response->is_success, 'Response Fails' );
243 is( $response->content,
244 q(FATAL ERROR: Couldn't go("TestApp"): Action has no namespace: cannot go() to a plain method or component, must be a :Action or some sort.),
251 TestApp::Controller::Action::Go->begin
252 TestApp::Controller::Action::Go->go_chained
253 TestApp::Controller::Action::Chained->begin
254 TestApp::Controller::Action::Chained->foo
255 TestApp::Controller::Action::Chained::Foo->spoon
256 TestApp::Controller::Action::Chained->end
259 my $expected = join( ", ", @expected );
261 ok( my $response = request('http://localhost/action/go/go_chained'), 'go to chained + subcontroller endpoint' );
262 is( $response->header('X-Catalyst-Executed'),
263 $expected, 'Executed actions' );
264 is( $response->content, '; 1', 'Content OK' );