CGI-Uploader

 view release on metacpan or  search on metacpan

t/meta.t  view on Meta::CPAN

use Test::More; 
Test::More->builder->no_ending(1);
use Config;
use Carp::Assert;
use lib 't/lib';
use strict;

use CGI::Uploader;
use DBI;
use CGI;
use HTTP::Request::Common;
use CGI::Uploader::Test;

$| = 1;

if (! $Config{d_fork} ) {
    plan skip_all => "fork not available on this platform";
}
else {
    plan tests => 12;

}

my ($DBH, $drv) = setup();

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;

$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',
            mime_type => 'mime_type',
            extension => 'extension',
            width     => 'width',
            height    => 'height',
            custom    => undef,
        }
	 );
	 ok($u, 'Uploader object creation');

     eval {
         my %entity_upload_extra = $u->store_upload(
             file_field  => 'test_file',
             src_file    => 't/test_file.txt',
             uploaded_mt => 'test/plain',
             file_name   => 'test_file.txt',
             shared_meta => { custom => 'custom_value' },
             );
         };
    is($@,'', 'store_upload() survives');

    my $imgs_with_custom_value =$DBH->selectrow_array(



( run in 1.144 second using v1.01-cache-2.11-cpan-98e64b0badf )