From 8cf2cd64c4c127737af84dc4fa9da7e47efcc933 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 Jul 2020 18:29:03 +0200 Subject: [PATCH] Bug 26145: Refactoring - Add tests Sponsored-by: Gerhard Sondermann Dialog e.K. (presseplus.de, presseshop.at, presseshop.ch) Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/CoverImages.t | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 t/db_dependent/Koha/CoverImages.t diff --git a/t/db_dependent/Koha/CoverImages.t b/t/db_dependent/Koha/CoverImages.t new file mode 100644 index 0000000000..69cfdf405a --- /dev/null +++ b/t/db_dependent/Koha/CoverImages.t @@ -0,0 +1,96 @@ +#!/usr/bin/perl + +# Copyright 2020 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 13; +use Test::Exception; + +use FindBin '$Bin'; + +use Koha::CoverImages; +use Koha::Database; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; + +my $biblio = $builder->build_sample_biblio; +my $item = $builder->build_sample_item; + +is( $biblio->cover_images->count, 0, 'No cover images yet' ); + +my $no_image = Koha::CoverImages->no_image; +is( ref($no_image), 'Koha::CoverImage', + 'no_image returns a Koha::CoverImage object' ); +is( $no_image->mimetype, 'image/gif', 'no_image is a gif image' ); +ok( $no_image->imagefile, 'no_image has imagefile set' ); +ok( $no_image->thumbnail, 'no_image has thumbnail set' ); + +my $logo_filepath = + "$Bin/../../../koha-tmpl/intranet-tmpl/prog/img/koha-logo.png"; +my $image = Koha::CoverImage->new( + { + biblionumber => $biblio->biblionumber, + src_image => GD::Image->new($logo_filepath) + } +)->store; + +is( $biblio->cover_images->count, 1, 'There is one cover image' ); +my $cover_image = $biblio->cover_images->next; +ok( $cover_image->imagefile, 'image is stored in imagefile' ); +ok( $cover_image->thumbnail, 'thumbnail has been generated' ); +is( $cover_image->mimetype, 'image/png', + 'mimetype has been correctly guessed' ); + +$image = Koha::CoverImage->new( + { + biblionumber => $biblio->biblionumber, + src_image => GD::Image->new($logo_filepath) + } +)->store; +is( $biblio->cover_images->count, 2, 'There are now two cover images' ); + +is( $item->cover_image, undef, 'No cover images yet' ); +$image = Koha::CoverImage->new( + { + itemnumber => $item->itemnumber, + src_image => GD::Image->new($logo_filepath) + } +)->store; +is( ref( $item->cover_image ), + 'Koha::CoverImage', + 'Koha::Item->cover_image returns a Koha::CoverImage object' ); + +throws_ok { + Koha::CoverImage->new( + { + biblionumber => $biblio->biblionumber, + itemnumber => $item->itemnumber, + src_image => GD::Image->new($logo_filepath) + } + )->store +} +'Koha::Exceptions::WrongParameter', + 'Exception is thrown if both biblionumber and itemnumber are passed'; + +$schema->storage->txn_rollback; -- 2.11.0