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