Commit | Line | Data |
50cc3183 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
42da66a9 |
7 | use lib "$FindBin::Bin/../lib"; |
50cc3183 |
8 | |
9 | our $iters; |
10 | |
6b25e555 |
11 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
12 | |
4065bc1e |
13 | use Test::More tests => 16 * $iters; |
50cc3183 |
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 | { |
28 | my @expected = qw[ |
29 | TestApp::Controller::Action::Default->begin |
30 | TestApp::Controller::Action::Default->default |
31 | TestApp::View::Dump::Request->process |
a0a66cb8 |
32 | TestApp::Controller::Root->end |
50cc3183 |
33 | ]; |
34 | |
35 | my $expected = join( ", ", @expected ); |
36 | |
37 | ok( my $response = request('http://localhost/action/default'), |
38 | 'Request' ); |
39 | ok( $response->is_success, 'Response Successful 2xx' ); |
40 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
41 | is( $response->header('X-Catalyst-Action'), 'default', 'Test Action' ); |
42 | is( |
43 | $response->header('X-Test-Class'), |
44 | 'TestApp::Controller::Action::Default', |
45 | 'Test Class' |
46 | ); |
47 | is( $response->header('X-Catalyst-Executed'), |
48 | $expected, 'Executed actions' ); |
49 | like( |
50 | $response->content, |
51 | qr/^bless\( .* 'Catalyst::Request' \)$/s, |
52 | 'Content is a serialized Catalyst::Request' |
53 | ); |
54 | |
55 | ok( $response = request('http://localhost/foo/bar/action'), 'Request' ); |
d1cbffb4 |
56 | is( $response->code, 500, 'Invalid URI returned 500' ); |
50cc3183 |
57 | } |
d1cbffb4 |
58 | |
50cc3183 |
59 | # test that args are passed properly to default |
60 | { |
61 | my $creq; |
d1cbffb4 |
62 | my $expected = [qw/action default arg1 arg2/]; |
63 | |
64 | ok( my $response = request('http://localhost/action/default/arg1/arg2'), |
65 | 'Request' ); |
66 | ok( |
67 | eval '$creq = ' . $response->content, |
68 | 'Unserialize Catalyst::Request' |
69 | ); |
50cc3183 |
70 | is_deeply( $creq->{arguments}, $expected, 'Arguments ok' ); |
71 | } |
4065bc1e |
72 | |
73 | |
74 | # Test that /foo and /foo/ both do the same thing |
75 | { |
76 | my @expected = qw[ |
77 | TestApp::Controller::Action->begin |
78 | TestApp::Controller::Action->default |
a0a66cb8 |
79 | TestApp::Controller::Root->end |
4065bc1e |
80 | ]; |
81 | |
82 | my $expected = join( ", ", @expected ); |
83 | |
84 | ok( my $response = request('http://localhost/action'), 'Request' ); |
85 | is( $response->header('X-Catalyst-Executed'), |
86 | $expected, |
87 | 'Executed actions for /action' |
88 | ); |
89 | |
90 | ok( $response = request('http://localhost/action/'), 'Request' ); |
91 | is( $response->header('X-Catalyst-Executed'), |
92 | $expected, |
93 | 'Executed actions for /action/' |
94 | ); |
95 | } |
50cc3183 |
96 | } |