7 use lib "$FindBin::Bin/lib";
9 use Test::More tests => 14;
13 use File::Spec::Functions;
17 my $path = catdir( getcwd(), 't', 'data', 'xforms' );
19 for ( my $i = 1; $i <= 2; $i++ ) {
21 my $test = sprintf( "%.3d", $i );
22 my $headers = PAML::LoadFile( catfile( $path, "$test-headers.pml" ) );
23 my $results = PAML::LoadFile( catfile( $path, "$test-results.pml" ) );
24 my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
25 my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
27 binmode $content, ':raw';
29 while ( $content->read( my $buffer, 1024 ) ) {
33 # Save tempnames for later deletion
36 for my $field ( keys %{ $body->upload } ) {
38 my $value = $body->upload->{$field};
40 for ( ( ref($value) eq 'ARRAY' ) ? @{$value} : $value ) {
41 push @temps, delete $_->{tempname};
45 is_deeply( $body->body, $results->{body}, "$test XForms body" );
46 is_deeply( $body->param, $results->{param}, "$test XForms param" );
47 is_deeply( $body->param_order, $results->{param_order} ? $results->{param_order} : [], "$test XForms param_order" );
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" );
53 ok( 1, "$test XForms start" );
55 cmp_ok( $body->state, 'eq', 'done', "$test XForms state" );
56 cmp_ok( $body->length, '==', $headers->{'Content-Length'}, "$test XForms length" );
58 # Clean up temp files created
59 unlink map { $_ } grep { defined $_ && -e $_ } @temps;