5 use lib "$FindBin::Bin/../lib";
9 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
11 use Test::More tests => 54 * $iters;
13 use Catalyst::Test 'TestApp';
15 if ( $ENV{CAT_BENCHMARK} ) {
17 Benchmark::timethis( $iters, \&run_tests );
27 # Test go to global private action
28 ok( my $response = request('http://localhost/action/go/global'),
30 ok( $response->is_success, 'Response Successful 2xx' );
31 is( $response->content_type, 'text/plain', 'Response Content-Type' );
32 is( $response->header('X-Catalyst-Action'),
33 'action/go/global', 'Main Class Action' );
38 TestApp::Controller::Action::Go->one
39 TestApp::Controller::Action::Go->two
40 TestApp::Controller::Action::Go->three
41 TestApp::Controller::Action::Go->four
42 TestApp::Controller::Action::Go->five
43 TestApp::View::Dump::Request->process
44 TestApp::Controller::Root->end
47 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
48 my $expected = join( ", ", @expected );
50 # Test go to chain of actions.
51 ok( my $response = request('http://localhost/action/go/one'),
53 ok( $response->is_success, 'Response Successful 2xx' );
54 is( $response->content_type, 'text/plain', 'Response Content-Type' );
55 is( $response->header('X-Catalyst-Action'),
56 'action/go/one', 'Test Action' );
58 $response->header('X-Test-Class'),
59 'TestApp::Controller::Action::Go',
62 is( $response->header('X-Catalyst-Executed'),
63 $expected, 'Executed actions' );
66 qr/^bless\( .* 'Catalyst::Request' \)$/s,
67 'Content is a serialized Catalyst::Request'
73 TestApp::Controller::Action::Go->go_die
74 TestApp::Controller::Action::Go->args
75 TestApp::Controller::Root->end
78 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
79 my $expected = join( ", ", @expected );
81 ok( my $response = request('http://localhost/action/go/go_die'),
83 ok( $response->is_success, 'Response Successful 2xx' );
84 is( $response->content_type, 'text/plain', 'Response Content-Type' );
85 is( $response->header('X-Catalyst-Action'),
86 'action/go/go_die', 'Test Action'
89 $response->header('X-Test-Class'),
90 'TestApp::Controller::Action::Go',
93 is( $response->header('X-Catalyst-Executed'),
94 $expected, 'Executed actions' );
95 is( $response->content, $Catalyst::GO, "Go died as expected" );
99 my $response = request('http://localhost/action/go/model'),
102 is( $response->content,
103 q[FATAL ERROR: Couldn't go("Model::Foo"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
104 q[go('Model::...') test]
109 my $response = request('http://localhost/action/go/view'),
112 is( $response->content,
113 q[FATAL ERROR: Couldn't go("View::Dump"): Action cannot _DISPATCH. Did you try to go() a non-controller action?],
114 q[go('View::...') test]
120 request('http://localhost/action/go/with_args/old'),
123 ok( $response->is_success, 'Response Successful 2xx' );
124 is( $response->content, 'old', 'go() with args (old)' );
129 my $response = request(
130 'http://localhost/action/go/with_method_and_args/new'),
131 'Request with args and method'
133 ok( $response->is_success, 'Response Successful 2xx' );
134 is( $response->content, 'new', 'go() with args (new)' );
137 # test go with embedded args
141 request('http://localhost/action/go/args_embed_relative'),
144 ok( $response->is_success, 'Response Successful 2xx' );
145 is( $response->content, 'ok', 'go() with args_embed_relative' );
151 request('http://localhost/action/go/args_embed_absolute'),
154 ok( $response->is_success, 'Response Successful 2xx' );
155 is( $response->content, 'ok', 'go() with args_embed_absolute' );
159 TestApp::Controller::Action::TestRelative->relative_go
160 TestApp::Controller::Action::Go->one
161 TestApp::Controller::Action::Go->two
162 TestApp::Controller::Action::Go->three
163 TestApp::Controller::Action::Go->four
164 TestApp::Controller::Action::Go->five
165 TestApp::View::Dump::Request->process
166 TestApp::Controller::Root->end
169 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
170 my $expected = join( ", ", @expected );
172 # Test go to chain of actions.
173 ok( my $response = request('http://localhost/action/relative/relative_go'),
175 ok( $response->is_success, 'Response Successful 2xx' );
176 is( $response->content_type, 'text/plain', 'Response Content-Type' );
177 is( $response->header('X-Catalyst-Action'),
178 'action/relative/relative_go', 'Test Action' );
180 $response->header('X-Test-Class'),
181 'TestApp::Controller::Action::Go',
184 is( $response->header('X-Catalyst-Executed'),
185 $expected, 'Executed actions' );
188 qr/^bless\( .* 'Catalyst::Request' \)$/s,
189 'Content is a serialized Catalyst::Request'
194 TestApp::Controller::Action::TestRelative->relative_go_two
195 TestApp::Controller::Action::Go->one
196 TestApp::Controller::Action::Go->two
197 TestApp::Controller::Action::Go->three
198 TestApp::Controller::Action::Go->four
199 TestApp::Controller::Action::Go->five
200 TestApp::View::Dump::Request->process
201 TestApp::Controller::Root->end
204 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
205 my $expected = join( ", ", @expected );
207 # Test go to chain of actions.
210 request('http://localhost/action/relative/relative_go_two'),
213 ok( $response->is_success, 'Response Successful 2xx' );
214 is( $response->content_type, 'text/plain', 'Response Content-Type' );
216 $response->header('X-Catalyst-Action'),
217 'action/relative/relative_go_two',
221 $response->header('X-Test-Class'),
222 'TestApp::Controller::Action::Go',
225 is( $response->header('X-Catalyst-Executed'),
226 $expected, 'Executed actions' );
229 qr/^bless\( .* 'Catalyst::Request' \)$/s,
230 'Content is a serialized Catalyst::Request'
234 # test class go -- MUST FAIL!
237 my $response = request(
238 'http://localhost/action/go/class_go_test_action'),
241 ok( !$response->is_success, 'Response Fails' );
242 is( $response->content,
243 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.),
250 TestApp::Controller::Action::Go->begin
251 TestApp::Controller::Action::Go->go_chained
252 TestApp::Controller::Action::Chained->begin
253 TestApp::Controller::Action::Chained->foo
254 TestApp::Controller::Action::Chained::Foo->spoon
255 TestApp::Controller::Action::Chained->end
258 my $expected = join( ", ", @expected );
260 ok( my $response = request('http://localhost/action/go/go_chained'), 'go to chained + subcontroller endpoint' );
261 is( $response->header('X-Catalyst-Executed'),
262 $expected, 'Executed actions' );
263 is( $response->content, 'captureme; arg1, arg2', 'Content OK' );