Add version 1.11 of HTTP::Body with new param_order functionality
[catagits/HTTP-Body.git] / t / 05urlencoded.t
CommitLineData
a9df1200 1#!perl
2
3use strict;
4use warnings;
5
712c90b5 6use FindBin;
7use lib "$FindBin::Bin/lib";
8
08160cca 9use Test::More tests => 37;
a9df1200 10
11use Cwd;
0a66fd23 12use Digest::MD5 qw(md5_hex);
a9df1200 13use HTTP::Body;
14use File::Spec::Functions;
15use IO::File;
712c90b5 16use PAML;
a9df1200 17
18my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
19
25f2a981 20for ( my $i = 1; $i <= 6; $i++ ) {
a9df1200 21
22 my $test = sprintf( "%.3d", $i );
712c90b5 23 my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) );
24 my $results = PAML::LoadFile( catfile( $path, "$test-results.pml" ) );
a9df1200 25 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
26 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
27
28 binmode $content, ':raw';
29
30 while ( $content->read( my $buffer, 1024 ) ) {
31 $body->add($buffer);
32 }
33
34 is_deeply( $body->body, $results->{body}, "$test UrlEncoded body" );
35 is_deeply( $body->param, $results->{param}, "$test UrlEncoded param" );
08160cca 36 is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test UrlEncoded param_order" );
a9df1200 37 is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
38 cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
0a66fd23 39 cmp_ok( $body->length, '==', $body->content_length, "$test UrlEncoded length" );
40
41 # Check trailing header on the chunked request
42 if ( $i == 3 ) {
43 my $content = IO::File->new( catfile( $path, "002-content.dat" ) );
4ba452d9 44 binmode $content;
0a66fd23 45 $content->read( my $buf, 4096 );
46 is( $body->trailing_headers->header('Content-MD5'), md5_hex($buf), "$test trailing header ok" );
47 }
a9df1200 48}