From 2c8f6399b012fd9b1002e3692e80344bacf490bf Mon Sep 17 00:00:00 2001 From: Bart Jorgensen Date: Thu, 23 Aug 2012 16:58:24 +1200 Subject: [PATCH] Bug 5327: Testing c4 Images Signed-off-by: Katrin Fischer Signed-off-by: Paul Poulain tested the 9 previous patches, that introduces many new unit tests using the Mock Module. --- t/Images.t | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 t/Images.t diff --git a/t/Images.t b/t/Images.t new file mode 100644 index 0000000000..c35d5bd443 --- /dev/null +++ b/t/Images.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# +#Testing C4 Images + +use strict; +use warnings; +use Test::More tests => 7; +use Test::MockModule; + +BEGIN { + use_ok('C4::Images'); +} + +my $module = new Test::MockModule('C4::Context'); +$module->mock( + '_new_dbh', + sub { + my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) + || die "Cannot create handle: $DBI::errstr\n"; + return $dbh; + } +); +my $images = [ + [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ], + [ 1, 2, 'gif', 'red', 001, 000 ], + [ 3, 2, 'jpeg', 'blue', 111, 110 ] +]; +my $dbh = C4::Context->dbh(); + +$dbh->{mock_add_resultset} = $images; + +my $image = C4::Images::RetrieveImage(); + +is( $image->{'imagenumber'}, 1, 'First imagenumber is 1' ); + +is( $image->{'mimetype'}, 'gif', 'First mimetype is red' ); + +is( $image->{'thumbnail'}, 001, 'First thumbnail is 001' ); + +$image = C4::Images::RetrieveImage(); + +$image = C4::Images::RetrieveImage(); + +$dbh->{mock_add_resultset} = $images; + +my @imagenumbers = C4::Images::ListImagesForBiblio(); + +is( $imagenumbers[0], 1, 'imagenumber is 1' ); + +is( $imagenumbers[1], 3, 'imagenumber is 3' ); + +$dbh->{mock_add_resultset} = $images; + +is( $imagenumbers[4], undef, 'imagenumber undef' ); -- 2.39.5