Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
3 |
# This Koha test module is a stub! |
4 |
# Add more tests here!!! |
5 |
|
6 |
use strict; |
7 |
use warnings; |
8 |
use MARC::Record; |
9 |
use C4::Biblio; |
10 |
|
11 |
use Test::More tests => 7; |
12 |
|
13 |
BEGIN { |
14 |
use_ok('C4::Items'); |
15 |
} |
16 |
|
17 |
# Helper biblio. |
18 |
diag("Creating biblio instance for testing."); |
19 |
my ($bibnum, $bibitemnum) = get_biblio(); |
20 |
|
21 |
# Add an item. |
22 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); |
23 |
cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber."); |
24 |
cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber."); |
25 |
|
26 |
# Get item. |
27 |
my $getitem = GetItem($itemnumber); |
28 |
cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); |
29 |
cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibnum, "Retrieved item has correct biblioitemnumber."); |
30 |
|
31 |
# Modify item; setting barcode. |
32 |
ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); |
33 |
my $moditem = GetItem($itemnumber); |
34 |
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); |
35 |
|
36 |
# Delete item. |
37 |
my $dbh = C4::Context->dbh; |
38 |
DelItem($dbh, $bibnum, $itemnumber); |
39 |
my $getdeleted = GetItem($itemnumber); |
40 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
41 |
|
42 |
# Delete helper Biblio. |
43 |
diag("Deleting biblio testing instance."); |
44 |
DelBiblio($bibnum); |
45 |
|
46 |
# Helper method to set up a Biblio. |
47 |
sub get_biblio { |
48 |
my $bib = MARC::Record->new(); |
49 |
$bib->append_fields( |
50 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
51 |
MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), |
52 |
); |
53 |
return ($bibnum, $bibitemnum) = AddBiblio($bib, ''); |
54 |
} |
55 |
|