Lines 97-118
subtest 'pickup_locations' => sub {
Link Here
|
97 |
branchnotes => 'zzzto', |
97 |
branchnotes => 'zzzto', |
98 |
})->store; |
98 |
})->store; |
99 |
|
99 |
|
100 |
my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY'); |
100 |
|
101 |
# Create item instance for testing. |
101 |
my $biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
102 |
my ($item_bibnum1, $item_bibitemnum1, $itemnumber1) |
|
|
103 |
= AddItem({ homebranch => $from->branchcode, |
104 |
holdingbranch => $from->branchcode } , $bibnum); |
105 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) |
106 |
= AddItem({ homebranch => $from->branchcode, |
107 |
holdingbranch => $from->branchcode } , $bibnum); |
108 |
my ($item_bibnum3, $item_bibitemnum3, $itemnumber3) |
109 |
= AddItem({ homebranch => $from->branchcode, |
110 |
holdingbranch => $from->branchcode } , $bibnum); |
111 |
my $item1 = Koha::Items->find($itemnumber1); |
112 |
my $item2 = Koha::Items->find($itemnumber2); |
113 |
my $item3 = Koha::Items->find($itemnumber3); |
114 |
my $biblio = Koha::Biblios->find($bibnum); |
115 |
my $itemtype = $biblio->itemtype; |
102 |
my $itemtype = $biblio->itemtype; |
|
|
103 |
my $item_info = { |
104 |
biblionumber => $biblio->biblionumber, |
105 |
library => $from->branchcode, |
106 |
itype => $itemtype |
107 |
}; |
108 |
my $item1 = $builder->build_sample_item({%$item_info}); |
109 |
my $item2 = $builder->build_sample_item({%$item_info}); |
110 |
my $item3 = $builder->build_sample_item({%$item_info}); |
116 |
|
111 |
|
117 |
subtest 'UseBranchTransferLimits = OFF' => sub { |
112 |
subtest 'UseBranchTransferLimits = OFF' => sub { |
118 |
plan tests => 5; |
113 |
plan tests => 5; |
Lines 129-135
subtest 'pickup_locations' => sub {
Link Here
|
129 |
my $total_pickup = Koha::Libraries->search({ |
124 |
my $total_pickup = Koha::Libraries->search({ |
130 |
pickup_location => 1 |
125 |
pickup_location => 1 |
131 |
})->count; |
126 |
})->count; |
132 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
127 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
133 |
is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system ' |
128 |
is(C4::Context->preference('UseBranchTransferLimits'), 0, 'Given system ' |
134 |
.'preference UseBranchTransferLimits is switched OFF,'); |
129 |
.'preference UseBranchTransferLimits is switched OFF,'); |
135 |
is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations ' |
130 |
is(@{$pickup}, $total_pickup, 'Then the total number of pickup locations ' |
Lines 137-151
subtest 'pickup_locations' => sub {
Link Here
|
137 |
|
132 |
|
138 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
133 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
139 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
134 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
140 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
135 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
141 |
is(@{$pickup}, $total_pickup, '...when ' |
136 |
is(@{$pickup}, $total_pickup, '...when ' |
142 |
.'BranchTransferLimitsType = itemtype and item-level_itypes = 1'); |
137 |
.'BranchTransferLimitsType = itemtype and item-level_itypes = 1'); |
143 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
138 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
144 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
139 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
145 |
is(@{$pickup}, $total_pickup, '...as well as when ' |
140 |
is(@{$pickup}, $total_pickup, '...as well as when ' |
146 |
.'BranchTransferLimitsType = itemtype and item-level_itypes = 0'); |
141 |
.'BranchTransferLimitsType = itemtype and item-level_itypes = 0'); |
147 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); |
142 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); |
148 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
143 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
149 |
is(@{$pickup}, $total_pickup, '...as well as when ' |
144 |
is(@{$pickup}, $total_pickup, '...as well as when ' |
150 |
.'BranchTransferLimitsType = ccode'); |
145 |
.'BranchTransferLimitsType = ccode'); |
151 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
146 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
Lines 175-181
subtest 'pickup_locations' => sub {
Link Here
|
175 |
'Given all items of a biblio have same the itemtype,'); |
170 |
'Given all items of a biblio have same the itemtype,'); |
176 |
is($limit->itemtype, $item1->effective_itemtype, 'and given there ' |
171 |
is($limit->itemtype, $item1->effective_itemtype, 'and given there ' |
177 |
.'is an existing transfer limit for that itemtype,'); |
172 |
.'is an existing transfer limit for that itemtype,'); |
178 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
173 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber}); |
179 |
my $found = 0; |
174 |
my $found = 0; |
180 |
foreach my $lib (@{$pickup}) { |
175 |
foreach my $lib (@{$pickup}) { |
181 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
176 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 204-210
subtest 'pickup_locations' => sub {
Link Here
|
204 |
is(Koha::Item::Transfer::Limits->search({ |
199 |
is(Koha::Item::Transfer::Limits->search({ |
205 |
itemtype => $item2->effective_itemtype })->count, 0, 'and it is' |
200 |
itemtype => $item2->effective_itemtype })->count, 0, 'and it is' |
206 |
.' not restricted by transfer limits,'); |
201 |
.' not restricted by transfer limits,'); |
207 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
202 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
208 |
$found = 0; |
203 |
$found = 0; |
209 |
foreach my $lib (@{$pickup}) { |
204 |
foreach my $lib (@{$pickup}) { |
210 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
205 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 223-229
subtest 'pickup_locations' => sub {
Link Here
|
223 |
is($found, 1, 'The same applies when asking pickup locations of ' |
218 |
is($found, 1, 'The same applies when asking pickup locations of ' |
224 |
.'a that particular item.'); |
219 |
.'a that particular item.'); |
225 |
Koha::Item::Transfer::Limits->delete; |
220 |
Koha::Item::Transfer::Limits->delete; |
226 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
221 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
227 |
$found = 0; |
222 |
$found = 0; |
228 |
foreach my $lib (@{$pickup}) { |
223 |
foreach my $lib (@{$pickup}) { |
229 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
224 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 261-267
subtest 'pickup_locations' => sub {
Link Here
|
261 |
'Given items use biblio-level itemtype,'); |
256 |
'Given items use biblio-level itemtype,'); |
262 |
is($limit->itemtype, $item1->effective_itemtype, 'and given there ' |
257 |
is($limit->itemtype, $item1->effective_itemtype, 'and given there ' |
263 |
.'is an existing transfer limit for that itemtype,'); |
258 |
.'is an existing transfer limit for that itemtype,'); |
264 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
259 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
265 |
my $found = 0; |
260 |
my $found = 0; |
266 |
foreach my $lib (@{$pickup}) { |
261 |
foreach my $lib (@{$pickup}) { |
267 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
262 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 285-291
subtest 'pickup_locations' => sub {
Link Here
|
285 |
is(@{$pickup}, $others, 'However, the number of other pickup ' |
280 |
is(@{$pickup}, $others, 'However, the number of other pickup ' |
286 |
.'libraries is correct.'); |
281 |
.'libraries is correct.'); |
287 |
Koha::Item::Transfer::Limits->delete; |
282 |
Koha::Item::Transfer::Limits->delete; |
288 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
283 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
289 |
$found = 0; |
284 |
$found = 0; |
290 |
foreach my $lib (@{$pickup}) { |
285 |
foreach my $lib (@{$pickup}) { |
291 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
286 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 302-308
subtest 'pickup_locations' => sub {
Link Here
|
302 |
ok($item1->itype ne $item1->effective_itemtype |
297 |
ok($item1->itype ne $item1->effective_itemtype |
303 |
&& $limit->itemtype eq $item1->itype, 'Given we have added a limit' |
298 |
&& $limit->itemtype eq $item1->itype, 'Given we have added a limit' |
304 |
.' matching ITEM-level itemtype,'); |
299 |
.' matching ITEM-level itemtype,'); |
305 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
300 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
306 |
$found = 0; |
301 |
$found = 0; |
307 |
foreach my $lib (@{$pickup}) { |
302 |
foreach my $lib (@{$pickup}) { |
308 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
303 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 338-344
subtest 'pickup_locations' => sub {
Link Here
|
338 |
|
333 |
|
339 |
is($limit->ccode, $item1->ccode, 'Given there ' |
334 |
is($limit->ccode, $item1->ccode, 'Given there ' |
340 |
.'is an existing transfer limit for that ccode,'); |
335 |
.'is an existing transfer limit for that ccode,'); |
341 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
336 |
my $pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
342 |
my $found = 0; |
337 |
my $found = 0; |
343 |
foreach my $lib (@{$pickup}) { |
338 |
foreach my $lib (@{$pickup}) { |
344 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
339 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 367-373
subtest 'pickup_locations' => sub {
Link Here
|
367 |
is(Koha::Item::Transfer::Limits->search({ |
362 |
is(Koha::Item::Transfer::Limits->search({ |
368 |
ccode => $item3->ccode })->count, 0, 'and it is' |
363 |
ccode => $item3->ccode })->count, 0, 'and it is' |
369 |
.' not restricted by transfer limits,'); |
364 |
.' not restricted by transfer limits,'); |
370 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
365 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
371 |
$found = 0; |
366 |
$found = 0; |
372 |
foreach my $lib (@{$pickup}) { |
367 |
foreach my $lib (@{$pickup}) { |
373 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
368 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 386-392
subtest 'pickup_locations' => sub {
Link Here
|
386 |
is($found, 1, 'The same applies when asking pickup locations of ' |
381 |
is($found, 1, 'The same applies when asking pickup locations of ' |
387 |
.'a that particular item.'); |
382 |
.'a that particular item.'); |
388 |
Koha::Item::Transfer::Limits->delete; |
383 |
Koha::Item::Transfer::Limits->delete; |
389 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $bibnum }); |
384 |
$pickup = Koha::Libraries->pickup_locations({ biblio => $biblio->biblionumber }); |
390 |
$found = 0; |
385 |
$found = 0; |
391 |
foreach my $lib (@{$pickup}) { |
386 |
foreach my $lib (@{$pickup}) { |
392 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
387 |
if ($lib->{'branchcode'} eq $limit->toBranch) { |
Lines 408-426
subtest 'pickup_locations' => sub {
Link Here
|
408 |
}; |
403 |
}; |
409 |
}; |
404 |
}; |
410 |
|
405 |
|
411 |
sub create_helper_biblio { |
|
|
412 |
my $itemtype = shift; |
413 |
my ($bibnum, $title, $bibitemnum); |
414 |
my $bib = MARC::Record->new(); |
415 |
$title = 'Silence in the library'; |
416 |
$bib->append_fields( |
417 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
418 |
MARC::Field->new('245', ' ', ' ', a => $title), |
419 |
MARC::Field->new('942', ' ', ' ', c => $itemtype), |
420 |
); |
421 |
return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); |
422 |
} |
423 |
|
424 |
$schema->storage->txn_rollback; |
406 |
$schema->storage->txn_rollback; |
425 |
|
407 |
|
426 |
subtest '->get_effective_marcorgcode' => sub { |
408 |
subtest '->get_effective_marcorgcode' => sub { |
427 |
- |
|
|