Create branch register_actions.
[catagits/Catalyst-Runtime.git] / t / aggregate / 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} || 1; }
12
13 use Test::More tests => 20*$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         my @expected = qw[
30           TestApp->index
31           TestApp->end
32         ];
33     
34         my $expected = join( ", ", @expected );
35         ok( my $response = request('http://localhost/'), 'root index' );
36         is( $response->header('X-Catalyst-Executed'),
37             $expected, 'Executed actions' );
38         is( $response->content, 'root index', 'root index ok' );
39         
40         ok( $response = request('http://localhost'), 'root index no slash' );
41         is( $response->content, 'root index', 'root index no slash ok' );
42     }
43     
44     # test first-level controller index
45     {
46         my @expected = qw[
47           TestApp::Controller::Index->index
48           TestApp->end
49         ];
50     
51         my $expected = join( ", ", @expected );
52         
53         ok( my $response = request('http://localhost/index/'), 'first-level controller index' );
54         is( $response->header('X-Catalyst-Executed'),
55             $expected, 'Executed actions' );
56         is( $response->content, 'Index index', 'first-level controller index ok' );
57         
58         ok( $response = request('http://localhost/index'), 'first-level controller index no slash' );
59         is( $response->header('X-Catalyst-Executed'),
60             $expected, 'Executed actions' );
61         is( $response->content, 'Index index', 'first-level controller index no slash ok' );        
62     }    
63     
64     # test second-level controller index
65     {
66         my @expected = qw[
67           TestApp::Controller::Action::Index->begin
68           TestApp::Controller::Action::Index->index
69           TestApp->end
70         ];
71     
72         my $expected = join( ", ", @expected );
73         
74         ok( my $response = request('http://localhost/action/index/'), 'second-level controller index' );
75         is( $response->header('X-Catalyst-Executed'),
76             $expected, 'Executed actions' );
77         is( $response->content, 'Action-Index index', 'second-level controller index ok' );
78         
79         ok( $response = request('http://localhost/action/index'), 'second-level controller index no slash' );
80         is( $response->header('X-Catalyst-Executed'),
81             $expected, 'Executed actions' );
82         is( $response->content, 'Action-Index index', 'second-level controller index no slash ok' );        
83     }
84     
85     # test controller default when index is present
86     {
87         my @expected = qw[
88           TestApp::Controller::Action::Index->begin
89           TestApp::Controller::Action::Index->default
90           TestApp->end
91         ];
92     
93         my $expected = join( ", ", @expected );
94         
95         ok( my $response = request('http://localhost/action/index/foo'), 'default with index' );
96         is( $response->header('X-Catalyst-Executed'),
97             $expected, 'Executed actions' );
98         is( $response->content, "Error - TestApp::Controller::Action\n", 'default with index ok' );
99     }
100 }