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