add the CGI "default_value for popup_menu()" fix from 3.45
[p5sagit/p5-mst-13.2.git] / lib / CGI / t / uploadInfo.t
CommitLineData
0078014a 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
11my $test_file;
12if($ENV{PERL_CORE}) {
13 chdir 't';
14 @INC = '../lib';
15 use File::Spec ();
16 $test_file = File::Spec->catfile(qw(.. lib CGI t), "upload_post_text.txt");
17} else {
18 use lib qw(. ./blib/lib ./blib/arch);
19 $test_file = "t/upload_post_text.txt";
20}
21
22use strict;
23
24use Test::More 'no_plan';
25
26use CGI;
27
28#-----------------------------------------------------------------------------
29# %ENV setup.
30#-----------------------------------------------------------------------------
31
f8a128a9 32my %myenv;
33
34BEGIN {
35 %myenv = (
36 'SCRIPT_NAME' => '/test.cgi',
37 'SERVER_NAME' => 'perl.org',
38 'HTTP_CONNECTION' => 'TE, close',
39 'REQUEST_METHOD' => 'POST',
40 'SCRIPT_URI' => 'http://www.perl.org/test.cgi',
41 'CONTENT_LENGTH' => 3285,
42 'SCRIPT_FILENAME' => '/home/usr/test.cgi',
43 'SERVER_SOFTWARE' => 'Apache/1.3.27 (Unix) ',
44 'HTTP_TE' => 'deflate,gzip;q=0.3',
45 'QUERY_STRING' => '',
46 'REMOTE_PORT' => '1855',
47 'HTTP_USER_AGENT' => 'Mozilla/5.0 (compatible; Konqueror/2.1.1; X11)',
48 'SERVER_PORT' => '80',
49 'REMOTE_ADDR' => '127.0.0.1',
50 'CONTENT_TYPE' => 'multipart/form-data; boundary=xYzZY',
51 'SERVER_PROTOCOL' => 'HTTP/1.1',
52 'PATH' => '/usr/local/bin:/usr/bin:/bin',
53 'REQUEST_URI' => '/test.cgi',
54 'GATEWAY_INTERFACE' => 'CGI/1.1',
55 'SCRIPT_URL' => '/test.cgi',
56 'SERVER_ADDR' => '127.0.0.1',
57 'DOCUMENT_ROOT' => '/home/develop',
58 'HTTP_HOST' => 'www.perl.org'
59 );
60
61 for my $key (keys %myenv) {
62 $ENV{$key} = $myenv{$key};
63 }
64}
65
66END {
67 for my $key (keys %myenv) {
68 delete $ENV{$key};
69 }
70}
71
0078014a 72
73#-----------------------------------------------------------------------------
74# Simulate the upload (really, multiple uploads contained in a single stream).
75#-----------------------------------------------------------------------------
76
77my $q;
78
79{
80 local *STDIN;
81 open STDIN, "< $test_file"
82 or die 'missing test file t/upload_post_text.txt';
83 binmode STDIN;
84 $q = CGI->new;
85}
86
87{
88 my $test = "uploadInfo: basic test";
89 my $fh = $q->upload('300x300_gif');
90 is( $q->uploadInfo($fh)->{'Content-Type'}, "image/gif", $test);
91}
92
93my $q2 = CGI->new;
94
95{
96 my $test = "uploadInfo: works with second object instance";
97 my $fh = $q2->upload('300x300_gif');
98 is( $q2->uploadInfo($fh)->{'Content-Type'}, "image/gif", $test);
99}
100