Add version 1.11 of HTTP::Body with new param_order functionality
[catagits/HTTP-Body.git] / t / 07xforms.t
CommitLineData
5940e4c7 1#!perl
2
3use strict;
4use warnings;
5
712c90b5 6use FindBin;
7use lib "$FindBin::Bin/lib";
8
08160cca 9use Test::More tests => 14;
5940e4c7 10
11use Cwd;
12use HTTP::Body;
13use File::Spec::Functions;
14use IO::File;
712c90b5 15use PAML;
5940e4c7 16
17my $path = catdir( getcwd(), 't', 'data', 'xforms' );
18
19for ( my $i = 1; $i <= 2; $i++ ) {
20
21 my $test = sprintf( "%.3d", $i );
712c90b5 22 my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) );
23 my $results = PAML::LoadFile( catfile( $path, "$test-results.pml" ) );
5940e4c7 24 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
25 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
26
27 binmode $content, ':raw';
28
29 while ( $content->read( my $buffer, 1024 ) ) {
30 $body->add($buffer);
31 }
32
33 # Save tempnames for later deletion
34 my @temps;
35
36 for my $field ( keys %{ $body->upload } ) {
37
38 my $value = $body->upload->{$field};
39
40 for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
41 push @temps, delete $_->{tempname};
42 }
43 }
44
45 is_deeply( $body->body, $results->{body}, "$test XForms body" );
46 is_deeply( $body->param, $results->{param}, "$test XForms param" );
08160cca 47 is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test XForms param_order" );
5940e4c7 48 is_deeply( $body->upload, $results->{upload}, "$test XForms upload" );
49 if ( $body->isa('HTTP::Body::XFormsMultipart') ) {
50 cmp_ok( $body->start, 'eq', $results->{start}, "$test XForms start" );
51 }
52 else {
53 ok( 1, "$test XForms start" );
54 }
55 cmp_ok( $body->state, 'eq', 'done', "$test XForms state" );
56 cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test XForms length" );
57
58 # Clean up temp files created
59 unlink map { $_ } grep { defined $_ && -e $_ } @temps;
60}