Added missing changes
[catagits/HTTP-Body.git] / t / 05urlencoded.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 => 37;
10
11 use Cwd;
12 use Digest::MD5 qw(md5_hex);
13 use HTTP::Body;
14 use File::Spec::Functions;
15 use IO::File;
16 use PAML;
17
18 my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
19
20 for ( my $i = 1; $i <= 6; $i++ ) {
21
22     my $test    = sprintf( "%.3d", $i );
23     my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) );
24     my $results = PAML::LoadFile( catfile( $path, "$test-results.pml" ) );
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" );
36         is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test UrlEncoded param_order" );
37     is_deeply( $body->upload, $results->{upload}, "$test UrlEncoded upload" );
38     cmp_ok( $body->state, 'eq', 'done', "$test UrlEncoded state" );
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" ) );
44         binmode $content;
45         $content->read( my $buf, 4096 );
46         is( $body->trailing_headers->header('Content-MD5'), md5_hex($buf), "$test trailing header ok" );
47     }
48 }