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

(-)a/Koha/Biblio.pm (+27 lines)
Lines 168-173 sub can_be_transferred { Link Here
168
    return 0;
168
    return 0;
169
}
169
}
170
170
171
172
=head3 pickup_locations
173
174
@pickup_locations = $biblio->pickup_locations( {patron => $patron } )
175
176
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)
177
and if item can be transfered to each pickup location.
178
179
=cut
180
181
sub pickup_locations {
182
    my ($self, $params) = @_;
183
184
    my $patron = $params->{patron};
185
186
    my @pickup_locations;
187
    foreach my $item_of_bib ($self->items) {
188
        push @pickup_locations, $item_of_bib->pickup_locations( {patron => $patron} );
189
    }
190
191
    my %seen;
192
    @pickup_locations =
193
      grep { !$seen{ $_->{branchcode} }++ } @pickup_locations;
194
195
    return wantarray ? @pickup_locations : \@pickup_locations;
196
}
197
171
=head3 hidden_in_opac
198
=head3 hidden_in_opac
172
199
173
my $bool = $biblio->hidden_in_opac({ [ rules => $rules ] })
200
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 295-300 sub can_be_transferred { Link Here
295
    })->count ? 0 : 1;
295
    })->count ? 0 : 1;
296
}
296
}
297
297
298
=head3 pickup_locations
299
300
@pickup_locations = $item->pickup_locations( {patron => $patron } )
301
302
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)
303
and if item can be transfered to each pickup location.
304
305
=cut
306
307
sub pickup_locations {
308
    my ($self, $params) = @_;
309
310
    my $patron = $params->{patron};
311
312
    my $circ_control_branch =
313
      C4::Circulation::_GetCircControlBranch( $self->unblessed(), $patron );
314
    my $branchitemrule =
315
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
316
317
    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
318
    my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch;
319
320
    #warn $branch_control.' '.$branchitemrule->{holdallowed}.' '.$library->branchcode.' '.$patron->branchcode;
321
322
    my @libs;
323
    if(defined $patron) {
324
        return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} );
325
        return @libs if $branchitemrule->{holdallowed} == 1 && $library->branchcode ne $patron->branchcode;
326
    }
327
328
    if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
329
        @libs  = $library->get_hold_libraries;
330
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
331
        push @libs, $self->home_branch;
332
    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
333
        push @libs, $self->holding_branch;
334
    } else {
335
        @libs = Koha::Libraries->search({
336
            pickup_location => 1
337
        }, {
338
            order_by => ['branchname']
339
        })->as_list;
340
    }
341
342
    my @pickup_locations;
343
    foreach my $library (@libs) {
344
        if ($library->pickup_location && $self->can_be_transferred({ to => $library })) {
345
            push @pickup_locations, $library->unblessed;
346
        }
347
    }
348
    return wantarray ? @pickup_locations : \@pickup_locations;
349
}
350
298
=head3 article_request_type
351
=head3 article_request_type
299
352
300
my $type = $item->article_request_type( $borrower )
353
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 (-1 / +343 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Items;
25
use C4::Items;
Lines 36-41 use t::lib::Mocks; Link Here
36
my $schema = Koha::Database->new->schema;
36
my $schema = Koha::Database->new->schema;
37
$schema->storage->txn_begin;
37
$schema->storage->txn_begin;
38
38
39
my $dbh     = C4::Context->dbh;
40
39
my $builder = t::lib::TestBuilder->new;
41
my $builder = t::lib::TestBuilder->new;
40
my $patron = $builder->build( { source => 'Borrower' } );
42
my $patron = $builder->build( { source => 'Borrower' } );
41
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
43
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
Lines 187-189 subtest 'can_be_transferred' => sub { Link Here
187
};
189
};
188
190
189
$schema->storage->txn_rollback;
191
$schema->storage->txn_rollback;
192
193
194
subtest 'pickup_locations' => sub {
195
    plan tests => 25;
196
197
    $schema->storage->txn_begin;
198
199
    # Cleanup database
200
    Koha::Holds->search->delete;
201
    Koha::Patrons->search->delete;
202
    Koha::Items->search->delete;
203
    Koha::Libraries->search->delete;
204
    $dbh->do('DELETE FROM issues');
205
    $dbh->do('DELETE FROM issuingrules');
206
    $dbh->do(
207
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
208
        VALUES (?, ?, ?, ?)},
209
        {},
210
        '*', '*', '*', 25
211
    );
212
    $dbh->do('DELETE FROM branch_item_rules');
213
    $dbh->do('DELETE FROM default_branch_circ_rules');
214
    $dbh->do('DELETE FROM default_branch_item_rules');
215
    $dbh->do('DELETE FROM default_circ_rules');
216
217
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
218
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
219
    my $root3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
220
221
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
222
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
223
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
224
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
225
    my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
226
    my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
227
228
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
229
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
230
231
    my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
232
    my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
233
234
    my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } );
235
    my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } );
236
237
    my $biblio1  = $builder->build_object( { class => 'Koha::Biblios' } );
238
    my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } );
239
    my $biblio2  = $builder->build_object( { class => 'Koha::Biblios' } );
240
    my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } );
241
242
    my $item1_1  = Koha::Item->new({
243
        biblionumber     => $biblio1->biblionumber,
244
        biblioitemnumber => $biblioitem1->biblioitemnumber,
245
        homebranch       => $library1->branchcode,
246
        holdingbranch    => $library2->branchcode,
247
        itype            => 'test',
248
        barcode          => "item11barcode",
249
    })->store;
250
251
    my $item1_3  = Koha::Item->new({
252
        biblionumber     => $biblio1->biblionumber,
253
        biblioitemnumber => $biblioitem1->biblioitemnumber,
254
        homebranch       => $library3->branchcode,
255
        holdingbranch    => $library4->branchcode,
256
        itype            => 'test',
257
        barcode          => "item13barcode",
258
    })->store;
259
260
    my $item2_2  = Koha::Item->new({
261
        biblionumber     => $biblio2->biblionumber,
262
        biblioitemnumber => $biblioitem2->biblioitemnumber,
263
        homebranch       => $library2->branchcode,
264
        holdingbranch    => $library1->branchcode,
265
        itype            => 'test',
266
        barcode          => "item22barcode",
267
    })->store;
268
269
    my $item2_3  = Koha::Item->new({
270
        biblionumber     => $biblio2->biblionumber,
271
        biblioitemnumber => $biblioitem2->biblioitemnumber,
272
        homebranch       => $library3->branchcode,
273
        holdingbranch    => $library3->branchcode,
274
        itype            => 'test',
275
        barcode          => "item23barcode",
276
    })->store;
277
278
    my $item2_4  = Koha::Item->new({
279
        biblionumber     => $biblio2->biblionumber,
280
        biblioitemnumber => $biblioitem2->biblioitemnumber,
281
        homebranch       => $library4->branchcode,
282
        holdingbranch    => $library4->branchcode,
283
        itype            => 'test',
284
        barcode          => "item24barcode",
285
    })->store;
286
287
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
288
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
289
290
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
291
292
    #Case 1: holdallowed any, hold_fulfillment_policy any
293
    $dbh->do(
294
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
295
        VALUES (?,?,?)},
296
        {},
297
        2, 'any', 'any'
298
    );
299
300
    my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
301
    my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
302
    my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
303
    my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
304
305
306
    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');
307
308
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
309
    $dbh->do(
310
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
311
        {},
312
        1, 'any'
313
    );
314
315
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
316
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
317
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
318
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
319
320
    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');
321
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
322
323
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
324
    $dbh->do(
325
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
326
        {},
327
        3, 'any'
328
    );
329
330
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
331
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
332
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
333
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
334
335
    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');
336
337
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
338
    $dbh->do(
339
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
340
        {},
341
        2, 'holdgroup'
342
    );
343
344
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
345
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
346
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
347
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
348
349
    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');
350
351
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
352
    $dbh->do(
353
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
354
        {},
355
        1, 'holdgroup'
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) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations');
364
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations');
365
366
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
367
    $dbh->do(
368
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
369
        {},
370
        3, 'holdgroup'
371
    );
372
373
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
374
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
375
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
376
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
377
378
    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');
379
380
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
381
    $dbh->do(
382
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
383
        {},
384
        2, 'homebranch'
385
    );
386
387
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
388
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
389
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
390
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
391
392
    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');
393
394
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
395
    $dbh->do(
396
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
397
        {},
398
        1, 'homebranch'
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) == 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');
407
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
408
409
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
410
    $dbh->do(
411
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
412
        {},
413
        3, 'homebranch'
414
    );
415
416
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
417
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
418
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
419
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
420
421
    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');
422
    ok(scalar(@pl_1_4) == 0, 'No pickup locations returned');
423
424
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
425
    $dbh->do(
426
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
427
        {},
428
        2, 'holdingbranch'
429
    );
430
431
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
432
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
433
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
434
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
435
436
    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');
437
438
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
439
    $dbh->do(
440
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
441
        {},
442
        1, 'holdingbranch'
443
    );
444
445
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
446
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
447
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
448
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
449
450
    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');
451
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned');
452
453
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
454
    $dbh->do(
455
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
456
        {},
457
        3, 'holdingbranch'
458
    );
459
460
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
461
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
462
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
463
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
464
465
    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');
466
467
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
468
469
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
470
    $dbh->do(
471
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
472
        {},
473
        1, 'any'
474
    );
475
476
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
477
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
478
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
479
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
480
481
    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');
482
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
483
484
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
485
    $dbh->do(
486
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
487
        {},
488
        1, 'holdgroup'
489
    );
490
491
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
492
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
493
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
494
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
495
496
    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');
497
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
498
499
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
500
    $dbh->do(
501
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
502
        {},
503
        1, 'homebranch'
504
    );
505
506
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
507
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
508
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
509
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
510
511
    #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');
512
    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');
513
    ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned');
514
515
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
516
    $dbh->do(
517
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
518
        {},
519
        1, 'holdingbranch'
520
    );
521
522
    @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } );
523
    @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } );
524
    @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } );
525
    @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } );
526
527
    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');
528
    ok(scalar(@pl_1_1) == 0, 'No pickup locations returned');
529
530
    $schema->storage->txn_rollback;
531
};
(-)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 $biblioitem  = $builder->build( { source => 'Biblioitem' } );
41
my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
39
my $library     = $builder->build( { source => 'Branch' } );
42
my $library     = $builder->build( { source => 'Branch' } );
Lines 184-186 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted th Link Here
184
187
185
$schema->storage->txn_rollback;
188
$schema->storage->txn_rollback;
186
189
187
- 
190
subtest 'pickup_locations' => sub {
191
    plan tests => 33;
192
193
    $schema->storage->txn_begin;
194
195
    # Cleanup database
196
    Koha::Holds->search->delete;
197
    Koha::Patrons->search->delete;
198
    Koha::Items->search->delete;
199
    Koha::Libraries->search->delete;
200
    $dbh->do('DELETE FROM issues');
201
    $dbh->do('DELETE FROM issuingrules');
202
    $dbh->do(
203
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
204
        VALUES (?, ?, ?, ?)},
205
        {},
206
        '*', '*', '*', 25
207
    );
208
    $dbh->do('DELETE FROM branch_item_rules');
209
    $dbh->do('DELETE FROM default_branch_circ_rules');
210
    $dbh->do('DELETE FROM default_branch_item_rules');
211
    $dbh->do('DELETE FROM default_circ_rules');
212
213
    my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
214
    my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1 } } );
215
216
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
217
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
218
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } );
219
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
220
221
    my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } );
222
    my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } );
223
224
    my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } );
225
    my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } );
226
227
    my $biblioitem  = $builder->build( { source => 'Biblioitem' } );
228
229
    my $item1  = Koha::Item->new({
230
        biblionumber     => $biblioitem->{biblionumber},
231
        biblioitemnumber => $biblioitem->{biblioitemnumber},
232
        homebranch       => $library1->branchcode,
233
        holdingbranch    => $library2->branchcode,
234
        itype            => 'test',
235
        barcode          => "item1barcode",
236
    })->store;
237
238
    my $item3  = Koha::Item->new({
239
        biblionumber     => $biblioitem->{biblionumber},
240
        biblioitemnumber => $biblioitem->{biblioitemnumber},
241
        homebranch       => $library3->branchcode,
242
        holdingbranch    => $library4->branchcode,
243
        itype            => 'test',
244
        barcode          => "item3barcode",
245
    })->store;
246
247
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } );
248
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } );
249
250
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
251
252
    #Case 1: holdallowed any, hold_fulfillment_policy any
253
    $dbh->do(
254
        q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch)
255
        VALUES (?,?,?)},
256
        {},
257
        2, 'any', 'any'
258
    );
259
260
    my @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
261
    my @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
262
    my @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
263
    my @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
264
265
    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');
266
267
    #Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch'
268
    $dbh->do(
269
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
270
        {},
271
        1, 'any'
272
    );
273
274
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
275
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
276
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
277
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
278
279
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
280
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
281
282
    #Case 3: holdallowed holdgroup, hold_fulfillment_policy any
283
    $dbh->do(
284
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
285
        {},
286
        3, 'any'
287
    );
288
289
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
290
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
291
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
292
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
293
294
    ok(scalar(@pl_1_1) == 3, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
295
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
296
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
297
298
    #Case 4: holdallowed any, hold_fulfillment_policy holdgroup
299
    $dbh->do(
300
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
301
        {},
302
        2, 'holdgroup'
303
    );
304
305
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
306
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
307
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
308
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
309
310
    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');
311
    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');
312
313
    #Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch'
314
    $dbh->do(
315
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
316
        {},
317
        1, 'holdgroup'
318
    );
319
320
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
321
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
322
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
323
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
324
325
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries in holdgroup that are pickup_locations');
326
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
327
328
    #Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup
329
    $dbh->do(
330
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
331
        {},
332
        3, 'holdgroup'
333
    );
334
335
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
336
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
337
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
338
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
339
340
    ok(scalar(@pl_1_1) == 2, 'Pickup location for patron 1 and item 1 renders all libraries that are pickup_locations');
341
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
342
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
343
344
    #Case 7: holdallowed any, hold_fulfillment_policy homebranch
345
    $dbh->do(
346
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
347
        {},
348
        2, 'homebranch'
349
    );
350
351
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
352
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
353
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
354
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
355
356
    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');
357
    ok(scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations, because library3 is not pickup_location');
358
359
    #Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch'
360
    $dbh->do(
361
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
362
        {},
363
        1, 'homebranch'
364
    );
365
366
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
367
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
368
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
369
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
370
371
    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');
372
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
373
374
    #Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch
375
    $dbh->do(
376
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
377
        {},
378
        3, 'homebranch'
379
    );
380
381
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
382
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
383
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
384
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
385
386
    ok(scalar(@pl_1_1) == 1, 'Pickup location for patron 1 and item 1 renders item\'s homebranch');
387
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
388
389
    #Case 10: holdallowed any, hold_fulfillment_policy holdingbranch
390
    $dbh->do(
391
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
392
        {},
393
        2, 'holdingbranch'
394
    );
395
396
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
397
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
398
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
399
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
400
401
    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');
402
    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');
403
404
405
    #Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch'
406
    $dbh->do(
407
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
408
        {},
409
        1, 'holdingbranch'
410
    );
411
412
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
413
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
414
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
415
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
416
417
    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');
418
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_3_4) == 0, 'Any other combination renders no locations');
419
420
    #Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch
421
    $dbh->do(
422
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
423
        {},
424
        3, 'holdingbranch'
425
    );
426
427
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
428
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
429
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
430
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
431
432
    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');
433
    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');
434
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0, 'Any other combination renders no locations');
435
436
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
437
438
    #Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch'
439
    $dbh->do(
440
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
441
        {},
442
        1, 'any'
443
    );
444
445
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
446
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
447
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
448
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
449
450
    ok(scalar(@pl_3_4) == 3, 'Pickup location for patron 4 and item 3 renders all libraries that are pickup_locations');
451
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
452
453
    #Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch'
454
    $dbh->do(
455
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
456
        {},
457
        1, 'holdgroup'
458
    );
459
460
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
461
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
462
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
463
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
464
465
    ok(scalar(@pl_3_4) == 1, 'Pickup location for patron 4 and item 3 renders all libraries in holdgroup that are pickup_locations');
466
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
467
468
    #Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch'
469
    $dbh->do(
470
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
471
        {},
472
        1, 'homebranch'
473
    );
474
475
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
476
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
477
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
478
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
479
480
    #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');
481
    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');
482
483
    #Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch'
484
    $dbh->do(
485
        q{UPDATE default_circ_rules set holdallowed = ?, hold_fulfillment_policy = ?},
486
        {},
487
        1, 'holdingbranch'
488
    );
489
490
    @pl_1_1 = $item1->pickup_locations( { patron => $patron1 } );
491
    @pl_1_4 = $item1->pickup_locations( { patron => $patron4 } );
492
    @pl_3_1 = $item3->pickup_locations( { patron => $patron1 } );
493
    @pl_3_4 = $item3->pickup_locations( { patron => $patron4 } );
494
495
    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');
496
    ok(scalar(@pl_1_4) == 0 && scalar(@pl_3_1) == 0 && scalar(@pl_1_1) == 0, 'Any other combination renders no locations');
497
498
    $schema->storage->txn_rollback;
499
};

Return to bug 22284