Bug 19300: Replace C4::Reserves::OPACItemHoldsAllowed - tests
This patch proves that we will not introduce trivial regression. With the same tests, we will execute the existing code and the new code. Test plan: With only this patch applied, prove t/db_dependent/Koha/IssuingRules.t should return green Followed test plan, patches worked as described Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
91990b04b9
commit
44ba06bdb1
|
|
@ -71,6 +71,18 @@ sub get_effective_issuing_rule {
|
|||
return $rule;
|
||||
}
|
||||
|
||||
sub get_opacitemholds_policy {
|
||||
my ( $class, $params ) = @_;
|
||||
|
||||
my $item = $params->{item};
|
||||
my $patron = $params->{patron};
|
||||
|
||||
return unless $item or $patron;
|
||||
|
||||
require C4::Reserves;
|
||||
return C4::Reserves::OPACItemHoldsAllowed( $item->unblessed, $patron->unblessed );
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 1;
|
||||
use Test::More tests => 2;
|
||||
|
||||
use Benchmark;
|
||||
|
||||
use Koha::IssuingRules;
|
||||
|
||||
use t::lib::TestBuilder;
|
||||
use t::lib::Mocks;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
$schema->storage->txn_begin;
|
||||
|
|
@ -241,6 +242,54 @@ subtest 'get_effective_issuing_rule' => sub {
|
|||
};
|
||||
};
|
||||
|
||||
subtest 'get_opacitemholds_policy' => sub {
|
||||
plan tests => 4;
|
||||
my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
|
||||
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
|
||||
my $library = $builder->build_object({ class => 'Koha::Libraries' });
|
||||
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
||||
my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
|
||||
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { itemtype => $itemtype->itemtype, biblionumber => $biblio->biblionumber } } );
|
||||
my $item = $builder->build_object(
|
||||
{ class => 'Koha::Items',
|
||||
value => {
|
||||
homebranch => $library->branchcode,
|
||||
holdingbranch => $library->branchcode,
|
||||
notforloan => 0,
|
||||
itemlost => 0,
|
||||
withdrawn => 0,
|
||||
biblionumber => $biblio->biblionumber,
|
||||
biblioitemnumber => $biblioitem->biblioitemnumber,
|
||||
itype => $itype->itemtype,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Koha::IssuingRules->delete;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => '*', branchcode => '*', opacitemholds => "N"})->store;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
|
||||
t::lib::Mocks::mock_preference('item-level_itypes', 1);
|
||||
my $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
|
||||
is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itype');
|
||||
t::lib::Mocks::mock_preference('item-level_itypes', 0);
|
||||
$opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
|
||||
is ( $opacitemholds, '', 'Patrons cannot place a hold on this itemtype');
|
||||
|
||||
Koha::IssuingRules->delete;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => '*', branchcode => '*', opacitemholds => "N"})->store;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
|
||||
Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
|
||||
t::lib::Mocks::mock_preference('item-level_itypes', 1);
|
||||
$opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
|
||||
is ( $opacitemholds, '', 'Patrons cannot place a hold on this itype');
|
||||
t::lib::Mocks::mock_preference('item-level_itypes', 0);
|
||||
$opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
|
||||
is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itemtype');
|
||||
|
||||
$patron->delete;
|
||||
};
|
||||
|
||||
sub _row_match {
|
||||
my ($rule, $branchcode, $categorycode, $itemtype) = @_;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue