From 47c5483307aa94aa90fcc1ace5d15a82153fc78b Mon Sep 17 00:00:00 2001 From: Stacey Walker Date: Mon, 11 Jun 2012 17:06:00 +0100 Subject: [PATCH] bug 5327: added some tests for C4/Items.pm Content-Type: text/plain; charset="UTF-8" Signed-off-by: Jared Camins-Esakov --- t/Items.t | 14 ------------ t/db_dependent/Items.t | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 14 deletions(-) delete mode 100755 t/Items.t create mode 100755 t/db_dependent/Items.t diff --git a/t/Items.t b/t/Items.t deleted file mode 100755 index c19cdc7..0000000 --- a/t/Items.t +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! - -use strict; -use warnings; - -use Test::More tests => 1; - -BEGIN { - use_ok('C4::Items'); -} - diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t new file mode 100755 index 0000000..be209c8 --- /dev/null +++ b/t/db_dependent/Items.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl +# +# This Koha test module is a stub! +# Add more tests here!!! + +use strict; +use warnings; +use MARC::Record; +use C4::Biblio; + +use Test::More tests => 7; + +BEGIN { + use_ok('C4::Items'); +} + +# Helper biblio. +diag("Creating biblio instance for testing."); +my ($bibnum, $bibitemnum) = get_biblio(); + +# Add an item. +my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); +cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); +cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); + +# Get item. +my $getitem = GetItem($itemnumber); +cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); +cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibnum, "Retrieved item has correct biblioitemnumber."); + +# Modify item; setting barcode. +ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); +my $moditem = GetItem($itemnumber); +cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); + +# Delete item. +my $dbh = C4::Context->dbh; +DelItem($dbh, $bibnum, $itemnumber); +my $getdeleted = GetItem($itemnumber); +is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); + +# Delete helper Biblio. +diag("Deleting biblio testing instance."); +DelBiblio($bibnum); + +# Helper method to set up a Biblio. +sub get_biblio { + my $bib = MARC::Record->new(); + $bib->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), + MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), + ); + return ($bibnum, $bibitemnum) = AddBiblio($bib, ''); +} -- 1.7.2.5