CGI-Uploader
view release on metacpan or search on metacpan
t/up_table_map.t view on Meta::CPAN
use Test::More;
Test::More->builder->no_ending(1);
use lib 'lib';
use strict;
use HTTP::Request::Common;
use lib 't/lib';
use CGI::Uploader::Test; # provides setup() and read_file()
use Config;
use CGI::Uploader;
use DBI;
use CGI;
use Test::DatabaseRow;
$| = 1;
if (! $Config{d_fork} ) {
plan skip_all => "fork not available on this platform";
}
else {
plan tests => 19;
}
# skip default table create to do it ourselves later.
my ($DBH,$drv) = setup(skip_create_uploader_table => 1);
my $req = &HTTP::Request::Common::POST(
'/dummy_location',
Content_Type => 'form-data',
Content => [
test_file => ["t/test_file.txt"],
]
);
# Useful in simulating an upload.
$ENV{REQUEST_METHOD} = 'POST';
$ENV{CONTENT_TYPE} = 'multipart/form-data';
$ENV{CONTENT_LENGTH} = $req->content_length;
if ( open( CHILD, "|-" ) ) {
print CHILD $req->content;
close CHILD;
exit 0;
}
my $q = new CGI;
ok(open(IN, "<create_uploader_table.".$drv.".sql"), 'opening SQL create file');
my $sql = join "\n", (<IN>);
# We alter the table to test our mapping
$sql =~ s/upload_id /upload_id_b /g;
$sql =~ s/mime_type/mime_type_b/;
$sql =~ s/extension/extension_b/;
$sql =~ s/width/width_b/;
$sql =~ s/height/height_b/;
$sql =~ s/gen_from_id/gen_from_id_b/;
my $created_up_table = $DBH->do($sql);
ok($created_up_table, 'creating uploads table');
$DBH->do("ALTER TABLE uploads ADD COLUMN custom char(64)");
my %imgs = (
'test_file' => {
gen_files => {
'test_file_gen' => {
transform_method => \&test_gen_transform,
}
},
},
);
my $u = CGI::Uploader->new(
updir_path=>'t/uploads',
updir_url=>'http://localhost/test',
dbh => $DBH,
query => $q,
spec => \%imgs,
up_table_map => {
upload_id => 'upload_id_b',
mime_type => 'mime_type_b',
extension => 'extension_b',
width => 'width_b',
height => 'height_b',
gen_from_id => 'gen_from_id_b',
( run in 0.538 second using v1.01-cache-2.11-cpan-437f7b0c052 )