Bugzilla – Attachment 116025 Details for
Bug 27068
HoldsQueue doesn't know how to use holds groups
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27068: Add unit tests
Bug-27068-Add-unit-tests.patch (text/plain), 8.45 KB, created by
Kyle M Hall (khall)
on 2021-01-29 12:49:38 UTC
(
hide
)
Description:
Bug 27068: Add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2021-01-29 12:49:38 UTC
Size:
8.45 KB
patch
obsolete
>From 057f8ae63a724e2bb3cb80d4fe251a3e4dd9c8a6 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Fri, 29 Jan 2021 07:48:21 -0500 >Subject: [PATCH] Bug 27068: Add unit tests > >--- > t/db_dependent/HoldsQueue.t | 148 +++++++++++++++++++++++++++++++++++- > 1 file changed, 147 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/HoldsQueue.t b/t/db_dependent/HoldsQueue.t >index 8c265f16b0..93c250bafd 100755 >--- a/t/db_dependent/HoldsQueue.t >+++ b/t/db_dependent/HoldsQueue.t >@@ -8,7 +8,7 @@ > > use Modern::Perl; > >-use Test::More tests => 55; >+use Test::More tests => 56; > use Data::Dumper; > > use C4::Calendar; >@@ -1522,6 +1522,152 @@ sub test_queue { > > } > >+subtest "Test _checkHoldPolicy" => sub { >+ plan tests => 25; >+ >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library_nongroup = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $category = $builder->build_object( { class => 'Koha::Patron::Categories', value => {exclude_from_local_holds_priority => 0} }); >+ my $patron = $builder->build_object( >+ { >+ class => "Koha::Patrons", >+ value => { >+ branchcode => $library1->branchcode, >+ categorycode => $category->categorycode, >+ } >+ } >+ ); >+ my $biblio = $builder->build_sample_biblio(); >+ my $item1 = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library1->branchcode, >+ exclude_from_local_holds_priority => 0, >+ } >+ ); >+ my $item2 = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library1->branchcode, >+ exclude_from_local_holds_priority => 0, >+ } >+ ); >+ >+ my $item3 = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $library1->branchcode, >+ exclude_from_local_holds_priority => 0, >+ } >+ ); >+ >+ $reserve_id = AddReserve( >+ { >+ branchcode => $item1->homebranch, >+ borrowernumber => $patron->borrowernumber, >+ biblionumber => $biblio->id, >+ priority => 1 >+ } >+ ); >+ ok( $reserve_id, "Hold was created"); >+ my $requests = C4::HoldsQueue::GetPendingHoldRequestsForBib($biblio->biblionumber); >+ is( @$requests, 1, "Got correct number of holds"); >+ >+ my $request = $requests->[0]; >+ is( $request->{biblionumber}, $biblio->id, "Hold has correct biblio"); >+ is( $request->{borrowernumber}, $patron->id, "Hold has correct borrower"); >+ is( $request->{borrowerbranch}, $patron->branchcode, "Hold has correct borrowerbranch"); >+ >+ my $hold = Koha::Holds->find( $reserve_id ); >+ ok( $hold, "Found hold" ); >+ >+ my $item = { >+ holdallowed => 1, >+ homebranch => $request->{borrowerbranch}, # library1 >+ hold_fulfillment_policy => 'any' >+ }; >+ >+ # Base case should work >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true" ); >+ >+ # Test holdallowed = 0 >+ $item->{holdallowed} = 0; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if holdallowed = 0" ); >+ >+ # Test holdallowed = 1 >+ $item->{holdallowed} = 1; >+ $item->{homebranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if holdallowed = 1 and branches do not match" ); >+ >+ $item->{homebranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if holdallowed = 1 and branches do match" ); >+ >+ # Test holdallowed = 3 >+ $item->{holdallowed} = 3; >+ $item->{homebranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if branchode doesn't match, holdallowed = 3 and no group branches exist" ); >+ $item->{homebranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if branchode matches, holdallowed = 3 and no group branches exist" ); >+ >+ # Create library groups hierarchy >+ my $rootgroup = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } ); >+ my $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); >+ my $group2 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode}} ); >+ >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if holdallowed = 3 and no group branches exist" ); >+ >+ $group1->delete; >+ >+ # Test hold_fulfillment_policy = holdgroup >+ $item->{hold_fulfillment_policy} = 'holdgroup'; >+ $item->{homebranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns true if library is not part of hold group, branches don't match and hfp = holdgroup" ); >+ $item->{homebranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is not part of hold group, branches match and hfp = holdgroup" ); >+ >+ $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); >+ >+ $item->{homebranch} = $library2->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); >+ $item->{homebranch} = $library1->id; >+ >+ $group1->delete; >+ >+ # Test hold_fulfillment_policy = homebranch >+ $item->{hold_fulfillment_policy} = 'homebranch'; >+ $item->{homebranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if hfp = homebranch and pickup branch != item homebranch" ); >+ >+ $item->{homebranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if hfp = homebranch and pickup branch = item homebranch" ); >+ >+ # Test hold_fulfillment_policy = holdingbranch >+ $item->{hold_fulfillment_policy} = 'holdingbranch'; >+ $item->{holdingbranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if hfp = holdingbranch and pickup branch != item holdingbranch" ); >+ >+ $item->{holdingbranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if hfp = holdingbranch and pickup branch = item holdingbranch" ); >+ >+ # Test hold_fulfillment_policy = patrongroup >+ $item->{hold_fulfillment_policy} = 'patrongroup'; >+ $item->{borrowerbranch} = $library1->id; >+ >+ $item->{homebranch} = $library_nongroup->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 0, "_checkHoldPolicy returns false if library is not part of hold group, branches don't match, hfp = patrongroup" ); >+ $item->{homebranch} = $request->{borrowerbranch}; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns false if library is not part of hold group, branches match, hfp = patrongroup" ); >+ >+ $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); >+ >+ $item->{borrowerbranch} = $library2->id; >+ is( C4::HoldsQueue::_checkHoldPolicy( $item, $request ), 1, "_checkHoldPolicy returns true if library is part of hold group with hfp = holdgroup" ); >+ $item->{borrowerbranch} = $library1->id; >+}; >+ > sub dump_records { > my ($tablename) = @_; > return $dbh->selectall_arrayref("SELECT * from $tablename where borrowernumber = ?", { Slice => {} }, $borrowernumber); >-- >2.24.1 (Apple Git-126)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27068
:
113900
|
114125
|
114140
|
114141
|
114142
|
115987
|
116022
|
116023
|
116024
|
116025
|
116026
|
116607
|
116608
|
116609
|
116610
|
116814
|
116815
|
116816
|
116817
|
117215