]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/live_t/34-lp1787968-cover-uploader.t
Stamping upgrade scripts and refifying baseline schema
[Evergreen.git] / Open-ILS / src / perlmods / live_t / 34-lp1787968-cover-uploader.t
1 #!perl
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;
8 use LWP::UserAgent;
9 use File::Fetch;
10 use HTTP::Request::Common qw(POST);
11 use FindBin;
12
13 diag("test image uploader");
14
15 my $U = 'OpenILS::Application::AppUtils';
16 my $script = OpenILS::Utils::TestUtils->new();
17 $script->bootstrap;
18
19 $script->authenticate({
20     username => 'admin',
21     password => 'demo123',
22     type => 'staff'});
23
24 my $authtoken = $script->authtoken;
25 ok($authtoken, 'Have an authtoken');
26
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">
32 #    </form>
33
34 my $target = "http://127.0.0.1/jacket-upload";
35
36 my $ua = new LWP::UserAgent;
37 my $req = POST(
38     $target,
39     Content_Type => 'multipart/form-data',
40     Content => [
41         # we're going for an image parse error
42         jacket_upload => [ "$FindBin::Bin/34-lp1787968-cover-uploader.t" ],
43         bib_record => 1,
44         ses => $authtoken
45     ]
46 );
47
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');
51
52 $ua = new LWP::UserAgent;
53 $req = POST(
54     $target,
55     Content_Type => 'multipart/form-data',
56     Content => [
57         jacket_upload => [ "$FindBin::Bin/../../../web/images/green_check.png" ],
58         bib_record => 1,
59         ses => $authtoken
60     ]
61 );
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');
65
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");
70
71 my $filetype = `file $file`;
72 diag($filetype);
73 ok( $filetype =~ /PNG/, 'Downloaded a PNG file from target location');