Commit | Line | Data |
50cc3183 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
a2e038a1 |
7 | use lib "$FindBin::Bin/lib"; |
50cc3183 |
8 | |
9 | our $iters; |
10 | |
11 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; } |
12 | |
13 | use Test::More tests => 12*$iters; |
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 |
32 | TestApp->end |
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' ); |
56 | is( $response->code, 404, 'Invalid URI returned 404' ); |
57 | } |
58 | |
59 | # test that args are passed properly to default |
60 | { |
61 | my $creq; |
62 | my $expected = [ qw/action default arg1 arg2/ ]; |
63 | |
64 | ok( my $response = request('http://localhost/action/default/arg1/arg2'), 'Request' ); |
65 | ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); |
66 | is_deeply( $creq->{arguments}, $expected, 'Arguments ok' ); |
67 | } |
68 | } |