Lines 19-25
use Modern::Perl;
Link Here
|
19 |
use Data::Dumper; |
19 |
use Data::Dumper; |
20 |
|
20 |
|
21 |
use MARC::Record; |
21 |
use MARC::Record; |
22 |
use C4::Items qw( ModItemTransfer GetHiddenItemnumbers GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); |
22 |
use C4::Items qw( ModItemTransfer GetItemsInfo SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); |
23 |
use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio ); |
23 |
use C4::Biblio qw( GetMarcFromKohaField EmbedItemsInMarcBiblio GetMarcBiblio AddBiblio ); |
24 |
use C4::Circulation qw( AddIssue ); |
24 |
use C4::Circulation qw( AddIssue ); |
25 |
use Koha::Items; |
25 |
use Koha::Items; |
Lines 190-294
subtest 'ModItemTransfer tests' => sub {
Link Here
|
190 |
$schema->storage->txn_rollback; |
190 |
$schema->storage->txn_rollback; |
191 |
}; |
191 |
}; |
192 |
|
192 |
|
193 |
subtest 'GetHiddenItemnumbers tests' => sub { |
|
|
194 |
|
195 |
plan tests => 11; |
196 |
|
197 |
# This sub is controlled by the OpacHiddenItems system preference. |
198 |
|
199 |
$schema->storage->txn_begin; |
200 |
|
201 |
my $builder = t::lib::TestBuilder->new; |
202 |
my $library1 = $builder->build({ |
203 |
source => 'Branch', |
204 |
}); |
205 |
|
206 |
my $library2 = $builder->build({ |
207 |
source => 'Branch', |
208 |
}); |
209 |
my $itemtype = $builder->build({ |
210 |
source => 'Itemtype', |
211 |
}); |
212 |
|
213 |
# Create a new biblio |
214 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
215 |
my $biblio = $builder->build_sample_biblio(); |
216 |
|
217 |
# Add two items |
218 |
my $item1_itemnumber = $builder->build_sample_item( |
219 |
{ |
220 |
biblionumber => $biblio->biblionumber, |
221 |
library => $library1->{branchcode}, |
222 |
withdrawn => 1, |
223 |
itype => $itemtype->{itemtype} |
224 |
} |
225 |
)->itemnumber; |
226 |
my $item2_itemnumber = $builder->build_sample_item( |
227 |
{ |
228 |
biblionumber => $biblio->biblionumber, |
229 |
library => $library2->{branchcode}, |
230 |
withdrawn => 0, |
231 |
itype => $itemtype->{itemtype} |
232 |
} |
233 |
)->itemnumber; |
234 |
my $opachiddenitems; |
235 |
my @itemnumbers = ($item1_itemnumber,$item2_itemnumber); |
236 |
my @hidden; |
237 |
my @items; |
238 |
push @items, Koha::Items->find( $item1_itemnumber )->unblessed; |
239 |
push @items, Koha::Items->find( $item2_itemnumber )->unblessed; |
240 |
|
241 |
# Empty OpacHiddenItems |
242 |
t::lib::Mocks::mock_preference('OpacHiddenItems',''); |
243 |
ok( !defined( GetHiddenItemnumbers( { items => \@items } ) ), |
244 |
"Hidden items list undef if OpacHiddenItems empty"); |
245 |
|
246 |
# Blank spaces |
247 |
t::lib::Mocks::mock_preference('OpacHiddenItems',' '); |
248 |
ok( scalar GetHiddenItemnumbers( { items => \@items } ) == 0, |
249 |
"Hidden items list empty if OpacHiddenItems only contains blanks"); |
250 |
|
251 |
# One variable / value |
252 |
$opachiddenitems = " |
253 |
withdrawn: [1]"; |
254 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
255 |
@hidden = GetHiddenItemnumbers( { items => \@items } ); |
256 |
ok( scalar @hidden == 1, "Only one hidden item"); |
257 |
is( $hidden[0], $item1_itemnumber, "withdrawn=1 is hidden"); |
258 |
|
259 |
# One variable, two values |
260 |
$opachiddenitems = " |
261 |
withdrawn: [1,0]"; |
262 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
263 |
@hidden = GetHiddenItemnumbers( { items => \@items } ); |
264 |
ok( scalar @hidden == 2, "Two items hidden"); |
265 |
is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and withdrawn=0 hidden"); |
266 |
|
267 |
# Two variables, a value each |
268 |
$opachiddenitems = " |
269 |
withdrawn: [1] |
270 |
homebranch: [$library2->{branchcode}] |
271 |
"; |
272 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
273 |
@hidden = GetHiddenItemnumbers( { items => \@items } ); |
274 |
ok( scalar @hidden == 2, "Two items hidden"); |
275 |
is_deeply( \@hidden, \@itemnumbers, "withdrawn=1 and homebranch library2 hidden"); |
276 |
|
277 |
# Override hidden with patron category |
278 |
t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'S' ); |
279 |
@hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'PT' } ); |
280 |
ok( scalar @hidden == 2, "Two items still hidden"); |
281 |
@hidden = GetHiddenItemnumbers( { items => \@items, borcat => 'S' } ); |
282 |
ok( scalar @hidden == 0, "Two items not hidden"); |
283 |
|
284 |
# Valid OpacHiddenItems, empty list |
285 |
@items = (); |
286 |
@hidden = GetHiddenItemnumbers( { items => \@items } ); |
287 |
ok( scalar @hidden == 0, "Empty items list, no item hidden"); |
288 |
|
289 |
$schema->storage->txn_rollback; |
290 |
}; |
291 |
|
292 |
subtest 'GetItemsInfo tests' => sub { |
193 |
subtest 'GetItemsInfo tests' => sub { |
293 |
|
194 |
|
294 |
plan tests => 9; |
195 |
plan tests => 9; |
295 |
- |
|
|