|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2020 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 13; |
| 23 |
use Test::Exception; |
| 24 |
|
| 25 |
use FindBin '$Bin'; |
| 26 |
|
| 27 |
use Koha::CoverImages; |
| 28 |
use Koha::Database; |
| 29 |
|
| 30 |
use t::lib::TestBuilder; |
| 31 |
|
| 32 |
my $schema = Koha::Database->new->schema; |
| 33 |
$schema->storage->txn_begin; |
| 34 |
|
| 35 |
my $builder = t::lib::TestBuilder->new; |
| 36 |
|
| 37 |
my $biblio = $builder->build_sample_biblio; |
| 38 |
my $item = $builder->build_sample_item; |
| 39 |
|
| 40 |
is( $biblio->cover_images->count, 0, 'No cover images yet' ); |
| 41 |
|
| 42 |
my $no_image = Koha::CoverImages->no_image; |
| 43 |
is( ref($no_image), 'Koha::CoverImage', |
| 44 |
'no_image returns a Koha::CoverImage object' ); |
| 45 |
is( $no_image->mimetype, 'image/gif', 'no_image is a gif image' ); |
| 46 |
ok( $no_image->imagefile, 'no_image has imagefile set' ); |
| 47 |
ok( $no_image->thumbnail, 'no_image has thumbnail set' ); |
| 48 |
|
| 49 |
my $logo_filepath = |
| 50 |
"$Bin/../../../koha-tmpl/intranet-tmpl/prog/img/koha-logo.png"; |
| 51 |
my $image = Koha::CoverImage->new( |
| 52 |
{ |
| 53 |
biblionumber => $biblio->biblionumber, |
| 54 |
src_image => GD::Image->new($logo_filepath) |
| 55 |
} |
| 56 |
)->store; |
| 57 |
|
| 58 |
is( $biblio->cover_images->count, 1, 'There is one cover image' ); |
| 59 |
my $cover_image = $biblio->cover_images->next; |
| 60 |
ok( $cover_image->imagefile, 'image is stored in imagefile' ); |
| 61 |
ok( $cover_image->thumbnail, 'thumbnail has been generated' ); |
| 62 |
is( $cover_image->mimetype, 'image/png', |
| 63 |
'mimetype has been correctly guessed' ); |
| 64 |
|
| 65 |
$image = Koha::CoverImage->new( |
| 66 |
{ |
| 67 |
biblionumber => $biblio->biblionumber, |
| 68 |
src_image => GD::Image->new($logo_filepath) |
| 69 |
} |
| 70 |
)->store; |
| 71 |
is( $biblio->cover_images->count, 2, 'There are now two cover images' ); |
| 72 |
|
| 73 |
is( $item->cover_image, undef, 'No cover images yet' ); |
| 74 |
$image = Koha::CoverImage->new( |
| 75 |
{ |
| 76 |
itemnumber => $item->itemnumber, |
| 77 |
src_image => GD::Image->new($logo_filepath) |
| 78 |
} |
| 79 |
)->store; |
| 80 |
is( ref( $item->cover_image ), |
| 81 |
'Koha::CoverImage', |
| 82 |
'Koha::Item->cover_image returns a Koha::CoverImage object' ); |
| 83 |
|
| 84 |
throws_ok { |
| 85 |
Koha::CoverImage->new( |
| 86 |
{ |
| 87 |
biblionumber => $biblio->biblionumber, |
| 88 |
itemnumber => $item->itemnumber, |
| 89 |
src_image => GD::Image->new($logo_filepath) |
| 90 |
} |
| 91 |
)->store |
| 92 |
} |
| 93 |
'Koha::Exceptions::WrongParameter', |
| 94 |
'Exception is thrown if both biblionumber and itemnumber are passed'; |
| 95 |
|
| 96 |
$schema->storage->txn_rollback; |