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

(-)a/Koha/IssuingRules.pm (+12 lines)
Lines 71-76 sub get_effective_issuing_rule { Link Here
71
    return $rule;
71
    return $rule;
72
}
72
}
73
73
74
sub get_opacitemholds_policy {
75
    my ( $class, $params ) = @_;
76
77
    my $item   = $params->{item};
78
    my $patron = $params->{patron};
79
80
    return unless $item or $patron;
81
82
    require C4::Reserves;
83
    return C4::Reserves::OPACItemHoldsAllowed( $item->unblessed, $patron->unblessed );
84
}
85
74
=head3 type
86
=head3 type
75
87
76
=cut
88
=cut
(-)a/t/db_dependent/Koha/IssuingRules.t (-2 / +50 lines)
Lines 19-31 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use Benchmark;
24
use Benchmark;
25
25
26
use Koha::IssuingRules;
26
use Koha::IssuingRules;
27
27
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
use t::lib::Mocks;
29
30
30
my $schema = Koha::Database->new->schema;
31
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
$schema->storage->txn_begin;
Lines 241-246 subtest 'get_effective_issuing_rule' => sub { Link Here
241
    };
242
    };
242
};
243
};
243
244
245
subtest 'get_opacitemholds_policy' => sub {
246
    plan tests => 4;
247
    my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
248
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
249
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
250
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
251
    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
252
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { itemtype => $itemtype->itemtype, biblionumber => $biblio->biblionumber } } );
253
    my $item = $builder->build_object(
254
        {   class  => 'Koha::Items',
255
            value  => {
256
                homebranch    => $library->branchcode,
257
                holdingbranch => $library->branchcode,
258
                notforloan    => 0,
259
                itemlost      => 0,
260
                withdrawn     => 0,
261
                biblionumber  => $biblio->biblionumber,
262
                biblioitemnumber => $biblioitem->biblioitemnumber,
263
                itype         => $itype->itemtype,
264
            }
265
        }
266
    );
267
268
    Koha::IssuingRules->delete;
269
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
270
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "Y"})->store;
271
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
272
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
273
    my $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
274
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itype');
275
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
276
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
277
    is ( $opacitemholds, '', 'Patrons cannot place a hold on this itemtype');
278
279
    Koha::IssuingRules->delete;
280
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
281
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "N"})->store;
282
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
283
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
284
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
285
    is ( $opacitemholds, '', 'Patrons cannot place a hold on this itype');
286
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
287
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
288
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itemtype');
289
290
    $patron->delete;
291
};
292
244
sub _row_match {
293
sub _row_match {
245
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
294
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
246
295
247
- 

Return to bug 19300