X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_engine_request_uploads.t;h=d2e95abd2be8eda8e040ef0ecb6f620c835fb7b2;hb=c45c5d3787dfb147d4bfb4542283f52a3223fa87;hp=bc437162c36ebc8f1719a6c9cbcada80b217d500;hpb=fdb3773e12efa92b61ce7e128ef0444f1d1b4e67;p=catagits%2FCatalyst-Runtime.git diff --git a/t/live_engine_request_uploads.t b/t/live_engine_request_uploads.t index bc43716..d2e95ab 100644 --- a/t/live_engine_request_uploads.t +++ b/t/live_engine_request_uploads.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 59; +use Test::More tests => 75; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -155,11 +155,19 @@ use HTTP::Request::Common; [ 'file' => ["$FindBin::Bin/catalyst_130pix.gif"], ] ); - # Sending wrong Content-Length here and see if subequent requests fail - $request->header('Content-Length' => $request->header('Content-Length') + 1); + # LWP will auto-correct Content-Length when using a remote server + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Using remote server', 2; + } - ok( my $response = request($request), 'Request' ); - ok( !$response->is_success, 'Response Error' ); + # Sending wrong Content-Length here and see if subequent requests fail + $request->header('Content-Length' => $request->header('Content-Length') + 1); + + ok( my $response = request($request), 'Request' ); + ok( !$response->is_success, 'Response Error' ); + } $request = POST( 'http://localhost/dump/request', @@ -169,9 +177,68 @@ use HTTP::Request::Common; 'file2' => ["$FindBin::Bin/catalyst_130pix.gif"], ] ); - ok( $response = request($request), 'Request' ); + 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/file1 => bless/, 'Upload with name file1'); like( $response->content, qr/file2 => bless/, 'Upload with name file2'); } + +{ + my $creq; + + my $request = POST( + 'http://localhost/dump/request/', + 'Content-Type' => 'form-data', + 'Content' => [ + 'testfile' => 'textfield value', + 'testfile' => ["$FindBin::Bin/catalyst_130pix.gif"], + ] + ); + + 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 $param = $creq->{parameters}->{testfile}; + + ok( @$param == 2, '2 values' ); + is( $param->[0], 'textfield value', 'correct value' ); + like( $param->[1], qr/\Qcatalyst_130pix.gif/, 'filename' ); + + for my $part ( $request->parts ) { + + my $disposition = $part->header('Content-Disposition'); + my %parameters = @{ ( split_header_words($disposition) )[0] }; + + next unless exists $parameters{filename}; + + my $upload = $creq->{uploads}->{ $parameters{name} }; + + isa_ok( $upload, 'Catalyst::Request::Upload' ); + + is( $upload->type, $part->content_type, 'Upload Content-Type' ); + is( $upload->size, length( $part->content ), 'Upload Content-Length' ); + is( $upload->filename, 'catalyst_130pix.gif' ); + } +}