From fe163cc9e5ba2b7b3127d923159829279cb4cce9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 11 Nov 2020 01:24:15 +0000 Subject: [PATCH] Bug 26963: Unit tests Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Item.t | 86 +++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 0309fa94f64..d24416045dd 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use C4::Biblio; use C4::Circulation; @@ -339,6 +339,90 @@ subtest 'pickup_locations' => sub { $schema->storage->txn_rollback; }; +subtest '_can_pickup_at' => sub { + plan tests =>8; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); + + my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); + my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); + my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } ); + my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); + + my $item = $builder->build_sample_item({ + homebranch => $library1->branchcode, + holdingbranch => $library1->branchcode, + ccode => "Gollum" + }); + + my @to = ( $library1, $library2, $library3, $library4 ); + + my $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations"); + + t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); + t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); + $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { + toBranch => $library2->branchcode, + fromBranch => $library1->branchcode, + itemtype => $item->itype, + ccode => undef, + } + }); + + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); + + $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { + toBranch => $library4->branchcode, + fromBranch => $library1->branchcode, + itemtype => $item->itype, + ccode => undef, + } + }); + + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); + + t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations"); + + $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { + toBranch => $library2->branchcode, + fromBranch => $library1->branchcode, + itemtype => undef, + ccode => $item->ccode, + } + }); + + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); + + $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { + toBranch => $library4->branchcode, + fromBranch => $library1->branchcode, + itemtype => undef, + ccode => $item->ccode, + } + }); + + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); + + + $pickup_locations = $item->_can_pickup_at({ to => \@to, from => $library2 }); + is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations"); + + t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); + + $pickup_locations = $item->_can_pickup_at({ to => \@to }); + is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations"); + +}; + subtest 'deletion' => sub { plan tests => 12; -- 2.29.2