use FindBin;
use lib "$FindBin::Bin/../lib";
-use Test::More tests => 88;
+use Test::More tests => 105;
use Catalyst::Test 'TestApp';
use Catalyst::Request;
use Catalyst::Request::Upload;
+use HTTP::Body::OctetStream;
use HTTP::Headers;
use HTTP::Headers::Util 'split_header_words';
use HTTP::Request::Common;
is( $creq->parameters->{ $upload->filename },
$upload->filename, 'legacy param method ok' );
- ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ SKIP:
+ {
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing for deleted file on remote server', 1;
+ }
+ ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ }
}
}
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' );
-
- ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ is( $upload->basename, $parameters{filename}, 'Upload basename' );
+
+ SKIP:
+ {
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing for deleted file on remote server', 1;
+ }
+ ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ }
}
}
ok( $response->is_success, 'Response Successful 2xx' );
is( $response->content_type, 'text/plain', 'Response Content-Type' );
is( $response->content, ( $request->parts )[0]->content, 'Content' );
+
+ # XXX: no way to test that temporary file for this test was deleted
}
{
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;
+ {
+ no strict 'refs';
+ ok(
+ eval '$creq = ' . $response->content,
+ 'Unserialize Catalyst::Request'
+ );
+ }
+
+ for my $file ( $creq->upload ) {
+ my $upload = $creq->upload($file);
+ SKIP:
+ {
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing for deleted file on remote server', 1;
+ }
+ ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ }
+ }
}
{
is( $upload->type, $part->content_type, 'Upload Content-Type' );
is( $upload->size, length( $part->content ), 'Upload Content-Length' );
- is( $upload->filename, 'catalyst_130pix.gif' );
+ is( $upload->filename, 'catalyst_130pix.gif', 'Upload Filename' );
+ is( $upload->basename, 'catalyst_130pix.gif', 'Upload basename' );
+
+ SKIP:
+ {
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing for deleted file on remote server', 1;
+ }
+ ok( !-e $upload->tempname, 'Upload temp file was deleted' );
+ }
}
}
-# test uploadtmp config var
+# Test PUT request with application/octet-stream file gets deleted
+
+{
+ my $body;
+
+ my $request = PUT(
+ 'http://localhost/dump/body/',
+ 'Content-Type' => 'application/octet-stream',
+ 'Content' => 'foobarbaz',
+ 'Content-Length' => 9,
+ );
+
+ 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\( .* 'HTTP::Body::OctetStream' \)/s,
+ 'Content is a serialized HTTP::Body::OctetStream'
+ );
+
+ {
+ no strict 'refs';
+ ok(
+ eval '$body = ' . substr( $response->content, 8 ), # FIXME - substr not needed in other test cases?
+ 'Unserialize HTTP::Body::OctetStream'
+ ) or warn $@;
+ }
+
+ isa_ok( $body, 'HTTP::Body::OctetStream' );
+ isa_ok($body->body, 'File::Temp');
+ SKIP:
+ {
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing for deleted file on remote server', 1;
+ }
+ ok( !-e $body->body->filename, 'Upload temp file was deleted' );
+ }
+}
+
+# test uploadtmp config var
+SKIP:
{
+ if ( $ENV{CATALYST_SERVER} ) {
+ skip 'Not testing uploadtmp on remote server', 14;
+ }
+
my $creq;
my $dir = "$FindBin::Bin/";
is( $upload->size, length( $part->content ), 'Upload Content-Length' );
like( $upload->tempname, qr{\Q$dir\E}, 'uploadtmp' );
+
+ ok( !-e $upload->tempname, 'Upload temp file was deleted' );
}
}