X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Fengine%2Frequest%2Fuploads.t;h=adb43d2c05110ad6e4c78cd6f0cebc75f83c1bb3;hp=5e82f849f2972bb7a9612537c4f487d317232de8;hb=1408d0a4a06459625233de7e50c38707c184a83f;hpb=2930d61024f0e6aad2efb559d082347c52147e5e diff --git a/t/engine/request/uploads.t b/t/engine/request/uploads.t index 5e82f84..adb43d2 100644 --- a/t/engine/request/uploads.t +++ b/t/engine/request/uploads.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../../lib"; -use Test::More tests => 18; +use Test::More tests => 39; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -55,3 +55,47 @@ use HTTP::Request::Common; is( $upload->size, length( $part->content ), 'Upload Content-Length' ); } } + +{ + my $creq; + + my $request = POST( 'http://localhost/dump/request/', + 'Content-Type' => 'multipart/form-data', + 'Content' => [ + 'testfile' => [ "$FindBin::Bin/cookies.t" ], + 'testfile' => [ "$FindBin::Bin/headers.t" ], + 'testfile' => [ "$FindBin::Bin/uploads.t" ], + ] + ); + + ok( my $response = request($request), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + like( $response->content, qr/^bless\( .* 'Catalyst::Request' \)$/s, 'Content is a serialized Catalyst::Request' ); + + { + no strict 'refs'; + ok( eval '$creq = ' . $response->content, 'Unserialize Catalyst::Request' ); + } + + isa_ok( $creq, 'Catalyst::Request' ); + is( $creq->method, 'POST', 'Catalyst::Request method' ); + is( $creq->content_type, 'multipart/form-data', 'Catalyst::Request Content-Type' ); + is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' ); + + my @parts = $request->parts; + + for ( my $i = 0; $i < @parts; $i++ ) { + + my $part = $parts[$i]; + my $disposition = $part->header('Content-Disposition'); + my %parameters = @{ ( split_header_words($disposition) )[0] }; + + my $upload = $creq->uploads->{ $parameters{name} }->[$i]; + + isa_ok( $upload, 'Catalyst::Request::Upload' ); + is( $upload->type, $part->content_type, 'Upload Content-Type' ); + is( $upload->filename, $parameters{filename}, 'Upload filename' ); + is( $upload->size, length( $part->content ), 'Upload Content-Length' ); + } +}