View | Details | Raw Unified | Return to bug 22284
Collapse All | Expand All

(-)a/Koha/Biblio.pm (+27 lines)
Lines 169-174 sub can_be_transferred { Link Here
169
    return 0;
169
    return 0;
170
}
170
}
171
171
172
173
=head3 pickup_locations
174
175
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
176
177
Returns possible pickup locations for this biblio items, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
178
and if item can be transfered to each pickup location.
179
180
=cut
181
182
sub pickup_locations {
183
    my ($self, $params) = @_;
184
185
    my $patron = $params->{patron};
186
187
    my @pickup_locations;
188
    foreach my $item_of_bib ($self->items) {
189
        push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} );
190
    }
191
192
    my %seen;
193
    @pickup_locations =
194
      grep { !$seen{ $_->{branchcode} }++ } @pickup_locations;
195
196
    return wantarray ? @pickup_locations : \@pickup_locations;
197
}
198
172
=head3 hidden_in_opac
199
=head3 hidden_in_opac
173
200
174
my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
201
my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
(-)a/Koha/Item.pm (-1 / +54 lines)
Lines 26-32 use Koha::Database; Link Here
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
27
27
28
use C4::Context;
28
use C4::Context;
29
29
use C4::Circulation;
30
use Koha::Checkouts;
30
use Koha::Checkouts;
31
use Koha::IssuingRules;
31
use Koha::IssuingRules;
32
use Koha::Item::Transfer::Limits;
32
use Koha::Item::Transfer::Limits;
Lines 294-299 sub can_be_transferred { Link Here
294
    })->count ? 0 : 1;
294
    })->count ? 0 : 1;
295
}
295
}
296
296
297
=head3 pickup_locations
298
299
@pickup_locations = $item->pickup_locations( {patron => $patron } )
300
301
Returns possible pickup locations for this item, according to patron's home library (if patron is defined and holds are allowed only from hold groups)
302
and if item can be transfered to each pickup location.
303
304
=cut
305
306
sub pickup_locations {
307
    my ($self, $params) = @_;
308
309
    my $patron = $params->{patron};
310
311
    my $circ_control_branch =
312
      C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron );
313
    my $branchitemrule =
314
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
315
316
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
317
    my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch;
318
319
    #warn $branch_control.' '.$branchitemrule->{holdallowed}.' '.$library->branchcode.' '.$patron->branchcode;
320
321
    my @libs;
322
    if(defined $patron) {
323
        return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} );
324
        return @libs if $branchitemrule->{holdallowed} == 1 && $library->branchcode ne $patron->branchcode;
325
    }
326
327
    if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
328
        @libs  = $library->get_hold_libraries;
329
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
330
        push @libs, $self->home_branch;
331
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
332
        push @libs, $self->holding_branch;
333
    } else {
334
        @libs = Koha::Libraries->search({
335
            pickup_location => 1
336
        }, {
337
            order_by => ['branchname']
338
        })->as_list;
339
    }
340
341
    my @pickup_locations;
342
    foreach my $library (@libs) {
343
        if ($library->pickup_location && $self->can_be_transferred({ to => $library })) {
344
            push @pickup_locations, $library->unblessed;
345
        }
346
    }
347
    return wantarray ? @pickup_locations : \@pickup_locations;
348
}
349
297
=head3 article_request_type
350
=head3 article_request_type
298
351
299
my $type = $item->article_request_type( $borrower )
352
my $type = $item->article_request_type( $borrower )
(-)a/Koha/Libraries.pm (-16 / +8 lines)
Lines 66-77 sub pickup_locations { Link Here
66
66
67
    my $item = $params->{'item'};
67
    my $item = $params->{'item'};
68
    my $biblio = $params->{'biblio'};
68
    my $biblio = $params->{'biblio'};
69
    my $patron = $params->{'patron'};
70
69
    if ($biblio && $item) {
71
    if ($biblio && $item) {
70
        Koha::Exceptions::BadParameter->throw(
72
        Koha::Exceptions::BadParameter->throw(
71
            error => "Koha::Libraries->pickup_locations takes either 'biblio' or "
73
            error => "Koha::Libraries->pickup_locations takes either 'biblio' or "
72
            ." 'item' as parameter, but not both."
74
            ." 'item' as parameter, but not both."
73
        );
75
        );
74
    }
76
    }
77
    unless (! defined $patron || ref($patron) eq 'Koha::Patron') {
78
        $patron = Koha::Items->find($patron);
79
    }
75
80
76
    # Select libraries that are configured as pickup locations
81
    # Select libraries that are configured as pickup locations
77
    my $libraries = $self->search({
82
    my $libraries = $self->search({
Lines 81-112 sub pickup_locations { Link Here
81
    });
86
    });
82
87
83
    return $libraries->unblessed unless $item or $biblio;
88
    return $libraries->unblessed unless $item or $biblio;
84
    return $libraries->unblessed
89
    if($item) {
85
        unless C4::Context->preference('UseBranchTransferLimits');
86
    my $limittype = C4::Context->preference('BranchTransferLimitsType');
87
88
    if ($item) {
89
        unless (ref($item) eq 'Koha::Item') {
90
        unless (ref($item) eq 'Koha::Item') {
90
            $item = Koha::Items->find($item);
91
            $item = Koha::Items->find($item);
91
            return $libraries->unblessed unless $item;
92
            return $libraries->unblessed unless $item;
92
        }
93
        }
94
        return $item->pickup_locations( {patron => $patron} );
93
    } else {
95
    } else {
94
        unless (ref($biblio) eq 'Koha::Biblio') {
96
        unless (ref($biblio) eq 'Koha::Biblio') {
95
            $biblio = Koha::Biblios->find($biblio);
97
            $biblio = Koha::Biblios->find($biblio);
96
            return $libraries->unblessed unless $biblio;
98
            return $libraries->unblessed unless $biblio;
97
        }
99
        }
100
        return $biblio->pickup_locations( {patron => $patron} );
98
    }
101
    }
99
100
    my @pickup_locations;
101
    foreach my $library ($libraries->as_list) {
102
        if ($item && $item->can_be_transferred({ to => $library })) {
103
            push @pickup_locations, $library->unblessed;
104
        } elsif ($biblio && $biblio->can_be_transferred({ to => $library })) {
105
            push @pickup_locations, $library->unblessed;
106
        }
107
    }
108
109
    return wantarray ? @pickup_locations : \@pickup_locations;
110
}
102
}
111
103
112
=head3 search_filtered
104
=head3 search_filtered
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt (-2 / +2 lines)
Lines 228-239 Link Here
228
                                                        <label for="branch_[% bibitemloo.biblionumber | html %]">Pick up location:</label>
228
                                                        <label for="branch_[% bibitemloo.biblionumber | html %]">Pick up location:</label>
229
                                                        [% UNLESS ( bibitemloo.holdable ) %]
229
                                                        [% UNLESS ( bibitemloo.holdable ) %]
230
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]" disabled="disabled">
230
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]" disabled="disabled">
231
                                                                [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber }, selected => branch }) %]
231
                                                                [% PROCESS options_for_libraries libraries => Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber, patron => logged_in_user }, selected => branch }) %]
232
                                                            </select>
232
                                                            </select>
233
                                                        [% ELSE %]
233
                                                        [% ELSE %]
234
                                                            [% SET at_least_one_library_not_available_for_pickup = 0 %]
234
                                                            [% SET at_least_one_library_not_available_for_pickup = 0 %]
235
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]">
235
                                                            <select name="branch" id="branch_[% bibitemloo.biblionumber | html %]">
236
                                                                [% FOREACH library IN Branches.all({ search_params => { pickup_location => 1 }, selected => branch }) %]
236
                                                                [% FOREACH library IN Branches.pickup_locations({ search_params => { biblio => bibitemloo.biblionumber, patron => logged_in_user }, selected => branch }) %]
237
                                                                    [% SET pickup_available_at = bibitemloo.not_available_at.grep(library.branchcode).size ? 0 : 1 %]
237
                                                                    [% SET pickup_available_at = bibitemloo.not_available_at.grep(library.branchcode).size ? 0 : 1 %]
238
                                                                    [% IF library.selected AND pickup_available_at %]
238
                                                                    [% IF library.selected AND pickup_available_at %]
239
                                                                        <option value="[% library.branchcode | html %]" selected="selected" >[% library.branchname | html %]</option>
239
                                                                        <option value="[% library.branchcode | html %]" selected="selected" >[% library.branchname | html %]</option>
(-)a/t/db_dependent/Koha/Biblios.t (+342 lines)
Lines 37-42 use t::lib::Mocks; Link Here
37
my $schema = Koha::Database->new->schema;
37
my $schema = Koha::Database->new->schema;
38
$schema->storage->txn_begin;
38
$schema->storage->txn_begin;
39
39
40
my $dbh     = C4::Context->dbh;
41
40
my $builder = t::lib::TestBuilder->new;
42
my $builder = t::lib::TestBuilder->new;
41
my $patron = $builder->build( { source => 'Borrower' } );
43
my $patron = $builder->build( { source => 'Borrower' } );
42
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
44
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
Lines 215-217 subtest 'custom_cover_image_url' => sub { Link Here
215
};
217
};
216
218
217
$schema->storage->txn_rollback;
219
$schema->storage->txn_rollback;
220
221
222
subtest 'pickup_locations' => sub {
223
    plan tests => 25;
224
225
    $schema->storage->txn_begin;
226
227
    # Cleanup database
228
    Koha::Holds->search->delete;
229
    Koha::Patrons->search->delete;
230
    Koha::Items->search->delete;
231
    Koha::Libraries->search->delete;
232
    $dbh->do('DELETE FROM issues');
233
    $dbh->do('DELETE FROM issuingrules');
234
    $dbh->do(
235
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
236
        VALUES (?, ?, ?, ?)},
237
        {},
238
        '*', '*', '*', 25
239
    );
240
    $dbh->do('DELETE FROM branch_item_rules');
241
    $dbh->do('DELETE FROM default_branch_circ_rules');
242
    $dbh->do('DELETE FROM default_branch_item_rules');
243
    $dbh->do('DELETE FROM default_circ_rules');
244
245
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
246
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
247
    my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
248
249
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
250
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
251
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
252
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
253
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
254
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
255
256
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
257
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
258
259
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
260
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
261
262
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
263
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
264
265
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios' } );
266
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
267
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios' } );
268
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
269
270
    my $item1_1  = Koha::Item->new({
271
        biblionumber     => $biblio1->biblionumber,
272
        biblioitemnumber => $biblioitem1->biblioitemnumber,
273
        homebranch       => $library1->branchcode,
274
        holdingbranch    => $library2->branchcode,
275
        itype            => 'test',
276
        barcode          => "item11barcode",
277
    })->store;
278
279
    my $item1_3  = Koha::Item->new({
280
        biblionumber     => $biblio1->biblionumber,
281
        biblioitemnumber => $biblioitem1->biblioitemnumber,
282
        homebranch       => $library3->branchcode,
283
        holdingbranch    => $library4->branchcode,
284
        itype            => 'test',
285
        barcode          => "item13barcode",
286
    })->store;
287
288
    my $item2_2  = Koha::Item->new({
289
        biblionumber     => $biblio2->biblionumber,
290
        biblioitemnumber => $biblioitem2->biblioitemnumber,
291
        homebranch       => $library2->branchcode,
292
        holdingbranch    => $library1->branchcode,
293
        itype            => 'test',
294
        barcode          => "item22barcode",
295
    })->store;
296
297
    my $item2_3  = Koha::Item->new({
298
        biblionumber     => $biblio2->biblionumber,
299
        biblioitemnumber => $biblioitem2->biblioitemnumber,
300
        homebranch       => $library3->branchcode,
301
        holdingbranch    => $library3->branchcode,
302
        itype            => 'test',
303
        barcode          => "item23barcode",
304
    })->store;
305
306
    my $item2_4  = Koha::Item->new({
307
        biblionumber     => $biblio2->biblionumber,
308
        biblioitemnumber => $biblioitem2->biblioitemnumber,
309
        homebranch       => $library4->branchcode,
310
        holdingbranch    => $library4->branchcode,
311
        itype            => 'test',
312
        barcode          => "item24barcode",
313
    })->store;
314
315
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
316
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
317
318
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
319
320
    #Case 1: holdallowed any, hold_fulfillment_policy any
321
    $dbh->do(
322
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
323
        VALUES (?,?,?)},
324
        {},
325
        2, 'any', 'any'
326
    );
327
328
    my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
329
    my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
330
    my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
331
    my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
332
333
334
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations');
335
336
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
337
    $dbh->do(
338
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
339
        {},
340
        1, 'any'
341
    );
342
343
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
344
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
345
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
346
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
347
348
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations, when item\'s hombebranch equals patron\' homebranch');
349
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
350
351
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
352
    $dbh->do(
353
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
354
        {},
355
        3, 'any'
356
    );
357
358
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
359
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
360
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
361
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
362
363
    ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup');
364
365
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
366
    $dbh->do(
367
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
368
        {},
369
        2, 'holdgroup'
370
    );
371
372
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
373
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
374
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
375
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
376
377
    ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations');
378
379
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
380
    $dbh->do(
381
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
382
        {},
383
        1, 'holdgroup'
384
    );
385
386
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
387
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
388
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
389
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
390
391
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations');
392
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
393
394
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
395
    $dbh->do(
396
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
397
        {},
398
        3, 'holdgroup'
399
    );
400
401
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
402
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
403
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
404
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
405
406
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations');
407
408
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
409
    $dbh->do(
410
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
411
        {},
412
        2, 'homebranch'
413
    );
414
415
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
416
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
417
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
418
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
419
420
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations');
421
422
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
423
    $dbh->do(
424
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
425
        {},
426
        1, 'homebranch'
427
    );
428
429
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
430
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
431
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
432
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
433
434
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Returns homebranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
435
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
436
437
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
438
    $dbh->do(
439
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
440
        {},
441
        3, 'homebranch'
442
    );
443
444
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
445
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
446
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
447
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
448
449
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio that are within patron\'s holdgroup, and that are pickup_locations');
450
    ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
451
452
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
453
    $dbh->do(
454
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
455
        {},
456
        2, 'holdingbranch'
457
    );
458
459
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
460
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
461
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
462
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
463
464
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations');
465
466
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
467
    $dbh->do(
468
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
469
        {},
470
        1, 'holdingbranch'
471
    );
472
473
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
474
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
475
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
476
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
477
478
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio, whose homebranch equals patron\'s, and that are pickup_locations');
479
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
480
481
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
482
    $dbh->do(
483
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
484
        {},
485
        3, 'holdingbranch'
486
    );
487
488
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
489
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
490
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
491
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
492
493
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1, 'Returns holdingbranch of items in biblio, whose homebranch are within patron\'s holdgroup, and that are pickup_locations');
494
495
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
496
497
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
498
    $dbh->do(
499
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
500
        {},
501
        1, 'any'
502
    );
503
504
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
505
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
506
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
507
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
508
509
    ok(scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries when item\'s holdingbranch equals patron\'s homebranch, and that are pickup_locations');
510
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
511
512
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
513
    $dbh->do(
514
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
515
        {},
516
        1, 'holdgroup'
517
    );
518
519
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
520
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
521
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
522
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
523
524
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
525
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
526
527
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
528
    $dbh->do(
529
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
530
        {},
531
        1, 'homebranch'
532
    );
533
534
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
535
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
536
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
537
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
538
539
    #ok(scalar(@pl_2_4) == 1 && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
540
    ok(scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio whose holdingbranch equals patron\'s homebranch, and that are pickup_locations');
541
    ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
542
543
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
544
    $dbh->do(
545
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
546
        {},
547
        1, 'holdingbranch'
548
    );
549
550
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
551
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
552
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
553
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
554
555
    ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations');
556
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
557
558
    $schema->storage->txn_rollback;
559
};
(-)a/t/db_dependent/Koha/Items.t (-1 / +313 lines)
Lines 23-28 use Test::More tests => 10; Link Here
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
26
use C4::Context;
26
use Koha::Item;
27
use Koha::Item;
27
use Koha::Item::Transfer::Limits;
28
use Koha::Item::Transfer::Limits;
28
use Koha::Items;
29
use Koha::Items;
Lines 34-39 use t::lib::Mocks; Link Here
34
my $schema = Koha::Database->new->schema;
35
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
36
$schema->storage->txn_begin;
36
37
38
my $dbh     = C4::Context->dbh;
39
37
my $builder     = t::lib::TestBuilder->new;
40
my $builder     = t::lib::TestBuilder->new;
38
my $library     = $builder->build( { source => 'Branch' } );
41
my $library     = $builder->build( { source => 'Branch' } );
39
my $nb_of_items = Koha::Items->search->count;
42
my $nb_of_items = Koha::Items->search->count;
Lines 175-177 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
175
178
176
$schema->storage->txn_rollback;
179
$schema->storage->txn_rollback;
177
180
178
- 
181
subtest 'pickup_locations' => sub {
182
    plan tests => 33;
183
184
    $schema->storage->txn_begin;
185
186
    # Cleanup database
187
    Koha::Holds->search->delete;
188
    Koha::Patrons->search->delete;
189
    Koha::Items->search->delete;
190
    Koha::Libraries->search->delete;
191
    $dbh->do('DELETE FROM issues');
192
    $dbh->do('DELETE FROM issuingrules');
193
    $dbh->do(
194
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
195
        VALUES (?, ?, ?, ?)},
196
        {},
197
        '*', '*', '*', 25
198
    );
199
    $dbh->do('DELETE FROM branch_item_rules');
200
    $dbh->do('DELETE FROM default_branch_circ_rules');
201
    $dbh->do('DELETE FROM default_branch_item_rules');
202
    $dbh->do('DELETE FROM default_circ_rules');
203
204
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
205
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
206
207
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
208
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
209
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
210
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
211
212
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
213
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
214
215
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
216
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
217
218
    my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
219
220
    my $item1  = Koha::Item->new({
221
        biblionumber     => $biblioitem->{biblionumber},
222
        biblioitemnumber => $biblioitem->{biblioitemnumber},
223
        homebranch       => $library1->branchcode,
224
        holdingbranch    => $library2->branchcode,
225
        itype            => 'test',
226
        barcode          => "item1barcode",
227
    })->store;
228
229
    my $item3  = Koha::Item->new({
230
        biblionumber     => $biblioitem->{biblionumber},
231
        biblioitemnumber => $biblioitem->{biblioitemnumber},
232
        homebranch       => $library3->branchcode,
233
        holdingbranch    => $library4->branchcode,
234
        itype            => 'test',
235
        barcode          => "item3barcode",
236
    })->store;
237
238
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
239
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
240
241
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
242
243
    #Case 1: holdallowed any, hold_fulfillment_policy any
244
    $dbh->do(
245
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
246
        VALUES (?,?,?)},
247
        {},
248
        2, 'any', 'any'
249
    );
250
251
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
252
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
253
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
254
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
255
256
    ok(scalar(@pl_1_1) == scalar(@pl_1_4) && scalar(@pl_1_1) == scalar(@pl_3_1) && scalar(@pl_1_1) == scalar(@pl_3_4), 'All combinations of patron/item renders the same number of locations');
257
258
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
259
    $dbh->do(
260
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
261
        {},
262
        1, 'any'
263
    );
264
265
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
266
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
267
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
268
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
269
270
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
271
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
272
273
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
274
    $dbh->do(
275
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
276
        {},
277
        3, 'any'
278
    );
279
280
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
281
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
282
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
283
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
284
285
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
286
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
287
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
288
289
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
290
    $dbh->do(
291
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
292
        {},
293
        2, 'holdgroup'
294
    );
295
296
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
297
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
298
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
299
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
300
301
    ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2, 'Pickup locations for item 1 renders all libraries in items\'s holdgroup that are pickup_locations');
302
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1, 'Pickup locations for item 3 renders all libraries in items\'s holdgroup that are pickup_locations');
303
304
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
305
    $dbh->do(
306
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
307
        {},
308
        1, 'holdgroup'
309
    );
310
311
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
312
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
313
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
314
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
315
316
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
317
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
318
319
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
320
    $dbh->do(
321
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
322
        {},
323
        3, 'holdgroup'
324
    );
325
326
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
327
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
328
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
329
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
330
331
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
332
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
333
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
334
335
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
336
    $dbh->do(
337
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
338
        {},
339
        2, 'homebranch'
340
    );
341
342
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
343
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
344
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
345
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
346
347
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_1_4[0]->{branchcode} eq $library1->id, 'Pickup locations for item 1 renders item\'s homelibrary');
348
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
349
350
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
351
    $dbh->do(
352
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
353
        {},
354
        1, 'homebranch'
355
    );
356
357
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
358
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
359
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
360
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
361
362
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
363
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
364
365
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
366
    $dbh->do(
367
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
368
        {},
369
        3, 'homebranch'
370
    );
371
372
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
373
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
374
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
375
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
376
377
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
378
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
379
380
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
381
    $dbh->do(
382
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
383
        {},
384
        2, 'holdingbranch'
385
    );
386
387
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
388
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
389
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
390
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
391
392
    ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode && $pl_1_4[0]->{branchcode} eq $library2->branchcode, 'Pickup locations for item 1 renders item\'s holding branch');
393
    ok(scalar(@pl_3_1) == 1 && scalar(@pl_3_4) == 1 && $pl_3_1[0]->{branchcode} eq $library4->branchcode && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup locations for item 3 renders item\'s holding branch');
394
395
396
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
397
    $dbh->do(
398
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
399
        {},
400
        1, 'holdingbranch'
401
    );
402
403
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
404
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
405
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
406
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
407
408
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
409
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
410
411
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
412
    $dbh->do(
413
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
414
        {},
415
        3, 'holdingbranch'
416
    );
417
418
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
419
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
420
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
421
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
422
423
    ok(scalar(@pl_1_1) == 1 && $pl_1_1[0]->{branchcode} eq $library2->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
424
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
425
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
426
427
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
428
429
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
430
    $dbh->do(
431
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
432
        {},
433
        1, 'any'
434
    );
435
436
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
437
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
438
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
439
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
440
441
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
442
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
443
444
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
445
    $dbh->do(
446
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
447
        {},
448
        1, 'holdgroup'
449
    );
450
451
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
452
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
453
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
454
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
455
456
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
457
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
458
459
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
460
    $dbh->do(
461
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
462
        {},
463
        1, 'homebranch'
464
    );
465
466
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
467
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
468
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
469
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
470
471
    #ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch');
472
    ok(scalar(@pl_3_4) == 0 && scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any combination of patron/item renders no locations');
473
474
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
475
    $dbh->do(
476
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
477
        {},
478
        1, 'holdingbranch'
479
    );
480
481
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
482
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
483
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
484
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
485
486
    ok(scalar(@pl_3_4) == 1 && $pl_3_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 1 and item 1 renders item\'s holding branch');
487
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
488
489
    $schema->storage->txn_rollback;
490
};

Return to bug 22284