actually document the new request body_data method
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_body_demand.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../lib";
8
9 use Test::More tests => 12;
10 use Catalyst::Test 'TestAppOnDemand';
11
12 use Catalyst::Request;
13 use HTTP::Headers;
14 use HTTP::Request::Common;
15
16 # Test a simple POST request to make sure body parsing
17 # works in on-demand mode.
18 SKIP:
19 {
20     if ( $ENV{CATALYST_SERVER} ) {
21         skip "Using remote server", 12;
22     }
23
24     {
25         my $params;
26
27         my $request = POST(
28             'http://localhost/body/query_params?wibble=wobble',
29             'Content-Type' => 'application/x-www-form-urlencoded',
30             'Content'      => 'foo=bar&baz=quux'
31         );
32
33         my $expected = { wibble => 'wobble' };
34
35         ok( my $response = request($request), 'Request' );
36         ok( $response->is_success, 'Response Successful 2xx' );
37
38         {
39             no strict 'refs';
40             ok(
41                 eval '$params = ' . $response->content,
42                 'Unserialize params'
43             );
44         }
45
46         is_deeply( $params, $expected, 'Catalyst::Request query parameters' );
47     }
48
49     {
50         my $params;
51
52         my $request = POST(
53             'http://localhost/body/params?wibble=wobble',
54             'Content-Type' => 'application/x-www-form-urlencoded',
55             'Content'      => 'foo=bar&baz=quux'
56         );
57     
58         my $expected = { foo => 'bar', baz => 'quux', wibble => 'wobble' };
59
60         ok( my $response = request($request), 'Request' );
61         ok( $response->is_success, 'Response Successful 2xx' );
62         {
63             no strict 'refs';
64             ok(
65                 eval '$params = ' . $response->content,
66                 'Unserialize params'
67             );
68         }
69
70         is_deeply( $params, $expected, 'Catalyst::Request body and query parameters' );
71     }
72
73     # Test reading chunks of the request body using $c->read
74     {
75         my $creq;
76     
77         my $request = POST(
78             'http://localhost/body/read',
79             'Content-Type' => 'text/plain',
80             'Content'      => 'x' x 105_000
81         );
82     
83         my $expected = '10000|10000|10000|10000|10000|10000|10000|10000|10000|10000|5000';
84
85         ok( my $response = request($request), 'Request' );
86         ok( $response->is_success, 'Response Successful 2xx' );
87         is( $response->content_type, 'text/plain', 'Response Content-Type' );
88         is( $response->content, $expected, 'Response Content' );
89     }
90 }