Commit | Line | Data |
50cc3183 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use FindBin; |
42da66a9 |
5 | use lib "$FindBin::Bin/../lib"; |
50cc3183 |
6 | |
7 | our $iters; |
8 | |
6b25e555 |
9 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
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[ |
a0a66cb8 |
28 | TestApp::Controller::Root->index |
29 | TestApp::Controller::Root->end |
50cc3183 |
30 | ]; |
b376e4ec |
31 | |
50cc3183 |
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' ); |
b376e4ec |
37 | |
50cc3183 |
38 | ok( $response = request('http://localhost'), 'root index no slash' ); |
39 | is( $response->content, 'root index', 'root index no slash ok' ); |
40 | } |
b376e4ec |
41 | |
50cc3183 |
42 | # test first-level controller index |
43 | { |
44 | my @expected = qw[ |
45 | TestApp::Controller::Index->index |
a0a66cb8 |
46 | TestApp::Controller::Root->end |
50cc3183 |
47 | ]; |
b376e4ec |
48 | |
50cc3183 |
49 | my $expected = join( ", ", @expected ); |
b376e4ec |
50 | |
50cc3183 |
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' ); |
b376e4ec |
55 | |
50cc3183 |
56 | ok( $response = request('http://localhost/index'), 'first-level controller index no slash' ); |
57 | is( $response->header('X-Catalyst-Executed'), |
58 | $expected, 'Executed actions' ); |
b376e4ec |
59 | is( $response->content, 'Index index', 'first-level controller index no slash ok' ); |
60 | } |
61 | |
50cc3183 |
62 | # test second-level controller index |
63 | { |
64 | my @expected = qw[ |
65 | TestApp::Controller::Action::Index->begin |
66 | TestApp::Controller::Action::Index->index |
a0a66cb8 |
67 | TestApp::Controller::Root->end |
50cc3183 |
68 | ]; |
b376e4ec |
69 | |
50cc3183 |
70 | my $expected = join( ", ", @expected ); |
b376e4ec |
71 | |
50cc3183 |
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' ); |
b376e4ec |
76 | |
50cc3183 |
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' ); |
b376e4ec |
80 | is( $response->content, 'Action-Index index', 'second-level controller index no slash ok' ); |
50cc3183 |
81 | } |
b376e4ec |
82 | |
50cc3183 |
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 |
a0a66cb8 |
88 | TestApp::Controller::Root->end |
50cc3183 |
89 | ]; |
b376e4ec |
90 | |
50cc3183 |
91 | my $expected = join( ", ", @expected ); |
b376e4ec |
92 | |
50cc3183 |
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 | } |