3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 use Test::More tests => 3;
30 my $dbh = C4::Context->dbh;
32 subtest 'General Add, Get and Del tests' => sub {
37 $dbh->{AutoCommit} = 0;
38 $dbh->{RaiseError} = 1;
41 diag("Creating biblio instance for testing.");
42 my ($bibnum, $bibitemnum) = get_biblio();
45 my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
46 cmp_ok($item_bibnum, '==', $bibnum, "New item is linked to correct biblionumber.");
47 cmp_ok($item_bibitemnum, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
50 my $getitem = GetItem($itemnumber);
51 cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber.");
52 cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
54 # Modify item; setting barcode.
55 ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
56 my $moditem = GetItem($itemnumber);
57 cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
60 DelItem($dbh, $bibnum, $itemnumber);
61 my $getdeleted = GetItem($itemnumber);
62 is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
67 subtest 'GetHiddenItemnumbers tests' => sub {
71 # This sub is controlled by the OpacHiddenItems system preference.
74 $dbh->{AutoCommit} = 0;
75 $dbh->{RaiseError} = 1;
78 my ($biblionumber, $biblioitemnumber) = get_biblio();
81 my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem(
82 { homebranch => 'CPL',
83 holdingbranch => 'CPL',
87 my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem(
88 { homebranch => 'MPL',
89 holdingbranch => 'MPL',
95 my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
98 push @items, GetItem( $item1_itemnumber );
99 push @items, GetItem( $item2_itemnumber );
101 # Empty OpacHiddenItems
102 C4::Context->set_preference('OpacHiddenItems','');
103 ok( !defined( GetHiddenItemnumbers( @items ) ),
104 "Hidden items list undef if OpacHiddenItems empty");
107 C4::Context->set_preference('OpacHiddenItems',' ');
108 ok( scalar GetHiddenItemnumbers( @items ) == 0,
109 "Hidden items list empty if OpacHiddenItems only contains blanks");
111 # One variable / value
114 C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
115 @hidden = GetHiddenItemnumbers( @items );
116 ok( scalar @hidden == 1, "Only one hidden item");
117 is( $hidden[0], $item1_itemnumber, "withdrawn=1 is hidden");
119 # One variable, two values
122 C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
123 @hidden = GetHiddenItemnumbers( @items );
124 ok( scalar @hidden == 2, "Two items hidden");
125 is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden");
127 # Two variables, a value each
132 C4::Context->set_preference( 'OpacHiddenItems', $opachiddenitems );
133 @hidden = GetHiddenItemnumbers( @items );
134 ok( scalar @hidden == 2, "Two items hidden");
135 is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch=MPL hidden");
137 # Valid OpacHiddenItems, empty list
139 @hidden = GetHiddenItemnumbers( @items );
140 ok( scalar @hidden == 0, "Empty items list, no item hidden");
145 # Helper method to set up a Biblio.
147 my $bib = MARC::Record->new();
149 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
150 MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
152 my ($bibnum, $bibitemnum) = AddBiblio($bib, '');
153 return ($bibnum, $bibitemnum);