X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Flive_engine_request_uploads.t;h=e2bb0d4081e5ad8216e3d75a361f54b679841da1;hp=88668fa1326fafb7d79fe6b2e999eb08a1d5ba5e;hb=2f3812528068bc1d9f7840067f0c03d36cd47e6d;hpb=afb82794328ff8da1efc0a4c37f3f3703c262c31 diff --git a/t/live_engine_request_uploads.t b/t/live_engine_request_uploads.t index 88668fa..e2bb0d4 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 => 75; +use Test::More tests => 88; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -14,6 +14,7 @@ use Catalyst::Request::Upload; use HTTP::Headers; use HTTP::Headers::Util 'split_header_words'; use HTTP::Request::Common; +use Path::Class::Dir; { my $creq; @@ -242,3 +243,63 @@ use HTTP::Request::Common; is( $upload->filename, 'catalyst_130pix.gif' ); } } + +# test uploadtmp config var + +{ + my $creq; + + my $dir = "$FindBin::Bin/"; + local TestApp->config->{ uploadtmp } = $dir; + $dir = Path::Class::Dir->new( $dir ); + + my $request = POST( + 'http://localhost/dump/request/', + 'Content-Type' => 'multipart/form-data', + 'Content' => [ + 'testfile' => ["$FindBin::Bin/live_engine_request_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' ); + + 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' ); + + like( $upload->tempname, qr{\Q$dir\E}, 'uploadtmp' ); + } +} +