actually document the new request body_data method
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_default.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
12
13 use Test::More tests => 16 * $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::Controller::Root->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, 500, 'Invalid URI returned 500' );
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'),
65             'Request' );
66         ok(
67             eval '$creq = ' . $response->content,
68             'Unserialize Catalyst::Request'
69         ) or fail("EXCEPTION $@ DESERIALIZING " . $response->content);
70         is_deeply( $creq->{arguments}, $expected, 'Arguments ok' );
71     }
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
79           TestApp::Controller::Root->end
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     }   
96 }