Lines 1-47
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
2 |
# |
3 |
# This Koha test module is a stub! |
3 |
# This file is part of Koha. |
4 |
# Add more tests here!!! |
4 |
# |
|
|
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 |
8 |
# version. |
9 |
# |
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. |
13 |
# |
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 |
17 |
# |
18 |
|
19 |
use Modern::Perl; |
5 |
|
20 |
|
6 |
use strict; |
|
|
7 |
use warnings; |
8 |
use MARC::Record; |
21 |
use MARC::Record; |
9 |
use C4::Biblio; |
22 |
use C4::Biblio; |
10 |
|
23 |
|
11 |
use Test::More tests => 7; |
24 |
use Test::More tests => 3; |
12 |
|
25 |
|
13 |
BEGIN { |
26 |
BEGIN { |
14 |
use_ok('C4::Items'); |
27 |
use_ok('C4::Items'); |
15 |
} |
28 |
} |
16 |
|
29 |
|
17 |
# Helper biblio. |
30 |
my $dbh = C4::Context->dbh; |
18 |
diag("Creating biblio instance for testing."); |
|
|
19 |
my ($bibnum, $bibitemnum) = get_biblio(); |
20 |
|
31 |
|
21 |
# Add an item. |
32 |
subtest 'General Add, Get and Del tests' => sub { |
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 |
|
33 |
|
26 |
# Get item. |
34 |
plan tests => 6; |
27 |
my $getitem = GetItem($itemnumber); |
|
|
28 |
cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber."); |
29 |
cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber."); |
30 |
|
35 |
|
31 |
# Modify item; setting barcode. |
36 |
# Start transaction |
32 |
ModItem({ barcode => '987654321' }, $bibnum, $itemnumber); |
37 |
$dbh->{AutoCommit} = 0; |
33 |
my $moditem = GetItem($itemnumber); |
38 |
$dbh->{RaiseError} = 1; |
34 |
cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.'); |
|
|
35 |
|
39 |
|
36 |
# Delete item. |
40 |
# Helper biblio. |
37 |
my $dbh = C4::Context->dbh; |
41 |
diag("Creating biblio instance for testing."); |
38 |
DelItem($dbh, $bibnum, $itemnumber); |
42 |
my ($bibnum, $bibitemnum) = get_biblio(); |
39 |
my $getdeleted = GetItem($itemnumber); |
43 |
|
40 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
44 |
# Add an item. |
|
|
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."); |
48 |
|
49 |
# Get item. |
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."); |
53 |
|
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'} . '.'); |
58 |
|
59 |
# Delete item. |
60 |
DelItem($dbh, $bibnum, $itemnumber); |
61 |
my $getdeleted = GetItem($itemnumber); |
62 |
is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected."); |
63 |
|
64 |
$dbh->rollback; |
65 |
}; |
66 |
|
67 |
subtest 'GetHiddenItemnumbers tests' => sub { |
68 |
|
69 |
plan tests => 9; |
70 |
|
71 |
# This sub is controlled by the OpacHiddenItems system preference. |
72 |
|
73 |
# Start transaction |
74 |
$dbh->{AutoCommit} = 0; |
75 |
$dbh->{RaiseError} = 1; |
76 |
|
77 |
# Create a new biblio |
78 |
my ($biblionumber, $biblioitemnumber) = get_biblio(); |
79 |
|
80 |
# Add two items |
81 |
my ($item1_bibnum, $item1_bibitemnum, $item1_itemnumber) = AddItem( |
82 |
{ homebranch => 'CPL', |
83 |
holdingbranch => 'CPL', |
84 |
withdrawn => 1 }, |
85 |
$biblionumber |
86 |
); |
87 |
my ($item2_bibnum, $item2_bibitemnum, $item2_itemnumber) = AddItem( |
88 |
{ homebranch => 'MPL', |
89 |
holdingbranch => 'MPL', |
90 |
withdrawn => 0 }, |
91 |
$biblionumber |
92 |
); |
93 |
|
94 |
my $opachiddenitems; |
95 |
my @itemnumbers = ($item1_itemnumber,$item2_itemnumber); |
96 |
my @hidden; |
97 |
my @items; |
98 |
push @items, GetItem( $item1_itemnumber ); |
99 |
push @items, GetItem( $item2_itemnumber ); |
100 |
|
101 |
# Empty OpacHiddenItems |
102 |
C4::Context->set_preference('OpacHiddenItems',''); |
103 |
ok( !defined( GetHiddenItemnumbers( @items ) ), |
104 |
"Hidden items list undef if OpacHiddenItems empty"); |
105 |
|
106 |
# Blank spaces |
107 |
C4::Context->set_preference('OpacHiddenItems',' '); |
108 |
ok( scalar GetHiddenItemnumbers( @items ) == 0, |
109 |
"Hidden items list empty if OpacHiddenItems only contains blanks"); |
110 |
|
111 |
# One variable / value |
112 |
$opachiddenitems = " |
113 |
withdrawn: [1]"; |
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"); |
118 |
|
119 |
# One variable, two values |
120 |
$opachiddenitems = " |
121 |
withdrawn: [1,0]"; |
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"); |
126 |
|
127 |
# Two variables, a value each |
128 |
$opachiddenitems = " |
129 |
withdrawn: [1] |
130 |
homebranch: [MPL] |
131 |
"; |
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"); |
136 |
|
137 |
# Valid OpacHiddenItems, empty list |
138 |
@items = (); |
139 |
@hidden = GetHiddenItemnumbers( @items ); |
140 |
ok( scalar @hidden == 0, "Empty items list, no item hidden"); |
41 |
|
141 |
|
42 |
# Delete helper Biblio. |
142 |
$dbh->rollback; |
43 |
diag("Deleting biblio testing instance."); |
143 |
}; |
44 |
DelBiblio($bibnum); |
|
|
45 |
|
144 |
|
46 |
# Helper method to set up a Biblio. |
145 |
# Helper method to set up a Biblio. |
47 |
sub get_biblio { |
146 |
sub get_biblio { |
Lines 50-54
sub get_biblio {
Link Here
|
50 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
149 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
51 |
MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), |
150 |
MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), |
52 |
); |
151 |
); |
53 |
return ($bibnum, $bibitemnum) = AddBiblio($bib, ''); |
152 |
my ($bibnum, $bibitemnum) = AddBiblio($bib, ''); |
|
|
153 |
return ($bibnum, $bibitemnum); |
54 |
} |
154 |
} |
55 |
- |
|
|