Changing default behavior of upload handling to stop taking over the upload extension...
[catagits/HTTP-Body.git] / t / 12rt88342-new.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use Test::More tests => 5;
10 use Test::Deep;
11
12 use Cwd;
13 use HTTP::Body;
14 use File::Spec::Functions;
15 use IO::File;
16 use PAML;
17 use File::Temp qw/ tempdir /;
18
19 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
20
21 {
22   my $uploads = uploads_for('015');
23
24         {
25                 my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload}{tempname} );        
26                 like(
27                         $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
28       'everything is file_temp_suffix now'
29                 );
30         }
31
32   {
33     my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload2}{tempname} );  
34     like(
35       $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
36       'everything is file_temp_suffix now'
37     );
38   }
39
40   {
41     my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload3}{tempname} );  
42     like(
43       $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
44       'everything is file_temp_suffix now'
45     );
46   }
47
48   {
49     my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload4}{tempname} );
50     like(
51       $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
52       'everything is file_temp_suffix now'
53     );
54   }
55
56   {
57     my ($volume,$directories,$file) = File::Spec->splitpath( $uploads->{upload5}{tempname} );
58     like(
59       $file, qr/\Q$HTTP::Body::MultiPart::file_temp_suffix\E$/,
60       'everything is file_temp_suffix now'
61     );
62   }
63 }
64
65 sub uploads_for {
66     my $number = shift;
67
68     my $headers = PAML::LoadFile( catfile( $path, "$number-headers.pml" ) );
69     my $content = IO::File->new( catfile( $path, "$number-content.dat" ) );
70     my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
71     my $tempdir = tempdir( 'XXXXXXX', CLEANUP => 1, DIR => File::Spec->tmpdir() );
72     $body->tmpdir($tempdir);
73
74     binmode $content, ':raw';
75
76     while ( $content->read( my $buffer, 1024 ) ) {
77         $body->add($buffer);
78     }
79
80     $body->cleanup(1);
81
82     return $body->upload;
83 }