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