From 44ba06bdb163ae70db53f7f7747735fb7c8f6ea9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 11 Sep 2017 13:59:11 -0300 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- Koha/IssuingRules.pm | 12 +++++++ t/db_dependent/Koha/IssuingRules.t | 51 +++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Koha/IssuingRules.pm b/Koha/IssuingRules.pm index e3664df753..20bbb45cd8 100644 --- a/Koha/IssuingRules.pm +++ b/Koha/IssuingRules.pm @@ -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 diff --git a/t/db_dependent/Koha/IssuingRules.t b/t/db_dependent/Koha/IssuingRules.t index 392cdecd24..0907a94239 100644 --- a/t/db_dependent/Koha/IssuingRules.t +++ b/t/db_dependent/Koha/IssuingRules.t @@ -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) = @_; -- 2.39.5