6be00f0c42a38fe02f2119f0adb65d52f2734d7d
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / index.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../../lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
12
13 use Test::More tests => 19*$iters;
14 use Catalyst::Test 'TestApp';
15
16 if ( $ENV{CAT_BENCHMARK} ) {
17     require Benchmark;
18     Benchmark::timethis( $iters, \&run_tests );
19 }
20 else {
21     for ( 1 .. $iters ) {
22         run_tests();
23     }
24 }
25
26 sub run_tests {
27     # test root index
28     {
29         ok( my $response = request('http://localhost/'), 'root index' );
30         is( $response->content, 'root index', 'root index ok' );
31         
32         ok( $response = request('http://localhost'), 'root index no slash' );
33         is( $response->content, 'root index', 'root index no slash ok' );
34     }
35     
36     # test first-level controller index
37     {
38         my @expected = qw[
39           TestApp::Controller::Index->index
40         ];
41     
42         my $expected = join( ", ", @expected );
43         
44         ok( my $response = request('http://localhost/index/'), 'first-level controller index' );
45         is( $response->header('X-Catalyst-Executed'),
46             $expected, 'Executed actions' );
47         is( $response->content, 'Index index', 'first-level controller index ok' );
48         
49         ok( $response = request('http://localhost/index'), 'first-level controller index no slash' );
50         is( $response->header('X-Catalyst-Executed'),
51             $expected, 'Executed actions' );
52         is( $response->content, 'Index index', 'first-level controller index no slash ok' );        
53     }    
54     
55     # test second-level controller index
56     {
57         my @expected = qw[
58           TestApp::Controller::Action::Index->begin
59           TestApp::Controller::Action::Index->index
60         ];
61     
62         my $expected = join( ", ", @expected );
63         
64         ok( my $response = request('http://localhost/action/index/'), 'second-level controller index' );
65         is( $response->header('X-Catalyst-Executed'),
66             $expected, 'Executed actions' );
67         is( $response->content, 'Action-Index index', 'second-level controller index ok' );
68         
69         ok( $response = request('http://localhost/action/index'), 'second-level controller index no slash' );
70         is( $response->header('X-Catalyst-Executed'),
71             $expected, 'Executed actions' );
72         is( $response->content, 'Action-Index index', 'second-level controller index no slash ok' );        
73     }
74     
75     # test controller default when index is present
76     {
77         my @expected = qw[
78           TestApp::Controller::Action::Index->begin
79           TestApp::Controller::Action::Index->default
80         ];
81     
82         my $expected = join( ", ", @expected );
83         
84         ok( my $response = request('http://localhost/action/index/foo'), 'default with index' );
85         is( $response->header('X-Catalyst-Executed'),
86             $expected, 'Executed actions' );
87         is( $response->content, "Error - TestApp::Controller::Action\n", 'default with index ok' );
88     }
89 }