2 use strict; use warnings;
3 use Test::More tests => 6;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use OpenILS::Utils::Fieldmapper;
10 use HTTP::Request::Common qw(POST);
13 diag("test image uploader");
15 my $U = 'OpenILS::Application::AppUtils';
16 my $script = OpenILS::Utils::TestUtils->new();
19 $script->authenticate({
21 password => 'demo123',
24 my $authtoken = $script->authtoken;
25 ok($authtoken, 'Have an authtoken');
27 # <form method="POST" enctype="multipart/form-data" action="/jacket-upload">
28 # <input type="file" name="jacket_upload">
29 # <input type="text" name="ses">
30 # <input type="text" name="bib_record">
31 # <input type="submit">
34 my $target = "http://127.0.0.1/jacket-upload";
36 my $ua = new LWP::UserAgent;
39 Content_Type => 'multipart/form-data',
41 # we're going for an image parse error
42 jacket_upload => [ "$FindBin::Bin/34-lp1787968-cover-uploader.t" ],
48 my $response = $ua->request($req);
49 ok( $response->is_success(), 'HTTP POST was successful');
50 ok( $response->content() eq '"parse error"', 'Received expected parse error for non-image upload');
52 $ua = new LWP::UserAgent;
55 Content_Type => 'multipart/form-data',
57 jacket_upload => [ "$FindBin::Bin/../../../web/images/green_check.png" ],
62 $response = $ua->request($req);
63 ok( $response->is_success(), 'HTTP POST was successful');
64 ok( $response->content() eq '1', 'Received expected response for an image upload');
66 my $url = 'http://localhost/opac/extras/ac/jacket/small/r/1';
67 my $ff = File::Fetch->new(uri => $url);
68 my $file = $ff->fetch( to => '/tmp' ) or die $ff->error;
69 diag("Downloaded $url as $file");
71 my $filetype = `file $file`;
73 ok( $filetype =~ /PNG/, 'Downloaded a PNG file from target location');