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