X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flive_engine_request_uploads.t;h=d2e95abd2be8eda8e040ef0ecb6f620c835fb7b2;hb=88ff44a29fe6beedcfe6046bbf2e62e1bc1a0207;hp=48a215d623170a68876ff092bb77d636027ee375;hpb=a2e038a1e9cbc0f1ea32b7087e6b47efe3af082f;p=catagits%2FCatalyst-Runtime.git diff --git a/t/live_engine_request_uploads.t b/t/live_engine_request_uploads.t index 48a215d..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 => 52; +use Test::More tests => 75; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -146,3 +146,99 @@ use HTTP::Request::Common; is( $response->content_type, 'text/plain', 'Response Content-Type' ); is( $response->content, ( $request->parts )[0]->content, 'Content' ); } + +{ + my $request = POST( + 'http://localhost/dump/request', + 'Content-Type' => 'multipart/form-data', + 'Content' => + [ 'file' => ["$FindBin::Bin/catalyst_130pix.gif"], ] + ); + + # LWP will auto-correct Content-Length when using a remote server + SKIP: + { + if ( $ENV{CATALYST_SERVER} ) { + skip 'Using remote server', 2; + } + + # 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', + 'Content-Type' => 'multipart/form-data', + 'Content' => + [ 'file1' => ["$FindBin::Bin/catalyst_130pix.gif"], + 'file2' => ["$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/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' ); + } +}