7 use lib "$FindBin::Bin/lib";
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
13 use Test::More tests => 50 * $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" );
102 request('http://localhost/action/go/with_args/old'),
105 ok( $response->is_success, 'Response Successful 2xx' );
106 is( $response->content, 'old' );
111 my $response = request(
112 'http://localhost/action/go/with_method_and_args/new'),
113 'Request with args and method'
115 ok( $response->is_success, 'Response Successful 2xx' );
116 is( $response->content, 'new' );
119 # test go with embedded args
123 request('http://localhost/action/go/args_embed_relative'),
126 ok( $response->is_success, 'Response Successful 2xx' );
127 is( $response->content, 'ok' );
133 request('http://localhost/action/go/args_embed_absolute'),
136 ok( $response->is_success, 'Response Successful 2xx' );
137 is( $response->content, 'ok' );
141 TestApp::Controller::Action::TestRelative->relative_go
142 TestApp::Controller::Action::Go->one
143 TestApp::Controller::Action::Go->two
144 TestApp::Controller::Action::Go->three
145 TestApp::Controller::Action::Go->four
146 TestApp::Controller::Action::Go->five
147 TestApp::View::Dump::Request->process
151 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
152 my $expected = join( ", ", @expected );
154 # Test go to chain of actions.
155 ok( my $response = request('http://localhost/action/relative/relative_go'),
157 ok( $response->is_success, 'Response Successful 2xx' );
158 is( $response->content_type, 'text/plain', 'Response Content-Type' );
159 is( $response->header('X-Catalyst-Action'),
160 'action/relative/relative_go', 'Test Action' );
162 $response->header('X-Test-Class'),
163 'TestApp::Controller::Action::Go',
166 is( $response->header('X-Catalyst-Executed'),
167 $expected, 'Executed actions' );
170 qr/^bless\( .* 'Catalyst::Request' \)$/s,
171 'Content is a serialized Catalyst::Request'
176 TestApp::Controller::Action::TestRelative->relative_go_two
177 TestApp::Controller::Action::Go->one
178 TestApp::Controller::Action::Go->two
179 TestApp::Controller::Action::Go->three
180 TestApp::Controller::Action::Go->four
181 TestApp::Controller::Action::Go->five
182 TestApp::View::Dump::Request->process
186 @expected = map { /Action/ ? (_begin($_), $_) : ($_) } @expected;
187 my $expected = join( ", ", @expected );
189 # Test go to chain of actions.
192 request('http://localhost/action/relative/relative_go_two'),
195 ok( $response->is_success, 'Response Successful 2xx' );
196 is( $response->content_type, 'text/plain', 'Response Content-Type' );
198 $response->header('X-Catalyst-Action'),
199 'action/relative/relative_go_two',
203 $response->header('X-Test-Class'),
204 'TestApp::Controller::Action::Go',
207 is( $response->header('X-Catalyst-Executed'),
208 $expected, 'Executed actions' );
211 qr/^bless\( .* 'Catalyst::Request' \)$/s,
212 'Content is a serialized Catalyst::Request'
216 # test class go -- MUST FAIL!
219 my $response = request(
220 'http://localhost/action/go/class_go_test_action'),
223 ok( !$response->is_success, 'Response Fails' );
224 is( $response->content, q(FATAL ERROR: Couldn't go to command "TestApp": Invalid action or component.), 'Error message' );
229 TestApp::Controller::Action::Go->begin
230 TestApp::Controller::Action::Go->go_chained
231 TestApp::Controller::Action::Chained->begin
232 TestApp::Controller::Action::Chained->foo
233 TestApp::Controller::Action::Chained::Foo->spoon
234 TestApp::Controller::Action::Chained->end
237 my $expected = join( ", ", @expected );
239 ok( my $response = request('http://localhost/action/go/go_chained'), 'go to chained + subcontroller endpoint' );
240 is( $response->header('X-Catalyst-Executed'),
241 $expected, 'Executed actions' );
242 is( $response->content, '; 1', 'Content OK' );