970429b8bbe14a0cf2ead0af1893be01dde1b8bf
[p5sagit/p5-mst-13.2.git] / ext / CGI / t / uploadInfo.t
1 #!/usr/local/bin/perl -w
2
3 #################################################################
4 #  Emanuele Zeppieri, Mark Stosberg                             #
5 #  Shamelessly stolen from Data::FormValidator and CGI::Upload  #
6 #################################################################
7
8 # Due to a bug in older versions of MakeMaker & Test::Harness, we must
9 # ensure the blib's are in @INC, else we might use the core CGI.pm
10 use lib qw(. ./blib/lib ./blib/arch);
11
12 use strict;
13
14 use Test::More 'no_plan';
15
16 use CGI;
17
18 #-----------------------------------------------------------------------------
19 # %ENV setup.
20 #-----------------------------------------------------------------------------
21
22 my %myenv;
23
24 BEGIN {
25     %myenv = (
26         'SCRIPT_NAME'       => '/test.cgi',
27         'SERVER_NAME'       => 'perl.org',
28         'HTTP_CONNECTION'   => 'TE, close',
29         'REQUEST_METHOD'    => 'POST',
30         'SCRIPT_URI'        => 'http://www.perl.org/test.cgi',
31         'CONTENT_LENGTH'    => 3285,
32         'SCRIPT_FILENAME'   => '/home/usr/test.cgi',
33         'SERVER_SOFTWARE'   => 'Apache/1.3.27 (Unix) ',
34         'HTTP_TE'           => 'deflate,gzip;q=0.3',
35         'QUERY_STRING'      => '',
36         'REMOTE_PORT'       => '1855',
37         'HTTP_USER_AGENT'   => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)',
38         'SERVER_PORT'       => '80',
39         'REMOTE_ADDR'       => '127.0.0.1',
40         'CONTENT_TYPE'      => 'multipart/form-data; boundary=xYzZY',
41         'SERVER_PROTOCOL'   => 'HTTP/1.1',
42         'PATH'              => '/usr/local/bin:/usr/bin:/bin',
43         'REQUEST_URI'       => '/test.cgi',
44         'GATEWAY_INTERFACE' => 'CGI/1.1',
45         'SCRIPT_URL'        => '/test.cgi',
46         'SERVER_ADDR'       => '127.0.0.1',
47         'DOCUMENT_ROOT'     => '/home/develop',
48         'HTTP_HOST'         => 'www.perl.org'
49     );
50
51     for my $key (keys %myenv) {
52         $ENV{$key} = $myenv{$key};
53     }
54 }
55
56 END {
57     for my $key (keys %myenv) {
58         delete $ENV{$key};
59     }
60 }
61
62
63 #-----------------------------------------------------------------------------
64 # Simulate the upload (really, multiple uploads contained in a single stream).
65 #-----------------------------------------------------------------------------
66
67 my $q;
68
69 {
70     local *STDIN;
71     open STDIN, '<t/upload_post_text.txt'
72         or die 'missing test file t/upload_post_text.txt';
73     binmode STDIN;
74     $q = CGI->new;
75 }
76
77 {
78     my $test = "uploadInfo: basic test";
79     my $fh = $q->upload('300x300_gif');
80     is( $q->uploadInfo($fh)->{'Content-Type'}, "image/gif", $test);
81 }
82
83 my $q2 = CGI->new;
84
85 {
86     my $test = "uploadInfo: works with second object instance";
87     my $fh = $q2->upload('300x300_gif');
88     is( $q2->uploadInfo($fh)->{'Content-Type'}, "image/gif", $test);
89 }
90