- Fixed CAT_BENCH_ITERS :)
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / default.t
CommitLineData
dd4e6fd2 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
9770ad56 7use lib "$FindBin::Bin/../../../lib";
dd4e6fd2 8
232fd394 9our $iters;
10
11BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
12
13use Test::More tests => 12*$iters;
dd4e6fd2 14use Catalyst::Test 'TestApp';
15
232fd394 16if ( $ENV{CAT_BENCHMARK} ) {
17 require Benchmark;
5a6c7ff6 18 Benchmark::timethis( $iters, \&run_tests );
232fd394 19}
20else {
21 for ( 1 .. $iters ) {
22 run_tests();
23 }
24}
25
26sub run_tests {
d8c66af5 27 {
28 my @expected = qw[
29 TestApp::Controller::Action::Default->begin
30 TestApp::Controller::Action::Default->default
31 TestApp::View::Dump::Request->process
32 ];
33
34 my $expected = join( ", ", @expected );
35
36 ok( my $response = request('http://localhost/action/default'),
37 'Request' );
38 ok( $response->is_success, 'Response Successful 2xx' );
39 is( $response->content_type, 'text/plain', 'Response Content-Type' );
40 is( $response->header('X-Catalyst-Action'), 'default', 'Test Action' );
41 is(
42 $response->header('X-Test-Class'),
43 'TestApp::Controller::Action::Default',
44 'Test Class'
45 );
46 is( $response->header('X-Catalyst-Executed'),
47 $expected, 'Executed actions' );
48 like(
49 $response->content,
50 qr/^bless\( .* 'Catalyst::Request' \)$/s,
51 'Content is a serialized Catalyst::Request'
52 );
53
54 ok( $response = request('http://localhost/foo/bar/action'), 'Request' );
55 is( $response->code, 404, 'Invalid URI returned 404' );
56 }
746380d1 57
58 # test that args are passed properly to default
59 {
60 my $creq;
61 my $expected = [ qw/action default arg1 arg2/ ];
62
63 ok( my $response = request('http://localhost/action/default/arg1/arg2'), 'Request' );
64 ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' );
65 is_deeply( $creq->{arguments}, $expected, 'Arguments ok' );
66 }
dd4e6fd2 67}