Bugzilla – Attachment 91147 Details for
Bug 16787
'Too many holds' message appears inappropriately and is missing data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16787: Add tests
Bug-16787-Add-tests.patch (text/plain), 9.68 KB, created by
Nick Clemens (kidclamp)
on 2019-07-01 14:02:39 UTC
(
hide
)
Description:
Bug 16787: Add tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2019-07-01 14:02:39 UTC
Size:
9.68 KB
patch
obsolete
>From 5140df720e726a8006b34a4d82e43078a4aa628f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 2 Nov 2017 12:59:46 -0300 >Subject: [PATCH] Bug 16787: Add tests > >--- > t/db_dependent/Holds.t | 167 +++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 135 insertions(+), 32 deletions(-) > >diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t >index 1515b4bef4..3eca3f3196 100755 >--- a/t/db_dependent/Holds.t >+++ b/t/db_dependent/Holds.t >@@ -7,7 +7,7 @@ use t::lib::TestBuilder; > > use C4::Context; > >-use Test::More tests => 59; >+use Test::More tests => 57; > use MARC::Record; > > use C4::Biblio; >@@ -242,7 +242,7 @@ is( $hold->priority, '6', "Test AlterPriority(), move to bottom" ); > my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); > my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) > = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); >-$dbh->do('DELETE FROM issuingrules'); >+delete_all_rules(); > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) > VALUES (?, ?, ?, ?, ?)}, >@@ -320,47 +320,141 @@ t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); > ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); > ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); > >-# Regression test for bug 9532 >-$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); >-($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber); >-AddReserve( >- $branch_1, >- $borrowernumbers[0], >- $biblio->biblionumber, >- '', >- 1, >-); >-is( >- CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', >- "cannot request item if policy that matches on item-level item type forbids it" >-); >-ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); >-ok( >- CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', >- "can request item if policy that matches on item type allows it" >-); >+subtest 'CanItemBeReserved' => sub { >+ plan tests => 2; > >-t::lib::Mocks::mock_preference('item-level_itypes', 0); >-ModItem({ itype => undef }, $item_bibnum, $itemnumber); >-ok( >- CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', >- "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" >-); >+ delete_all_rules(); >+ >+ my $itemtype_can = $builder->build({source => "Itemtype"})->{itemtype}; >+ my $itemtype_cant = $builder->build({source => "Itemtype"})->{itemtype}; >+ >+ $dbh->do( >+ q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, >+ '*', '*', $itemtype_cant, 0, 99 >+ ); >+ $dbh->do( >+ q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, >+ '*', '*', $itemtype_can, 2, 2 >+ ); >+ >+ subtest 'noReservesAllowed' => sub { >+ plan tests => 4; >+ >+ my $biblionumber_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant })->biblionumber; >+ my $biblionumber_can = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; >+ my ( undef, undef, $itemnumber_1_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_cannot); >+ my ( undef, undef, $itemnumber_1_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblionumber_cannot); >+ >+ my ( undef, undef, $itemnumber_2_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_can); >+ my ( undef, undef, $itemnumber_2_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblionumber_can); >+ >+ Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; >+ >+ t::lib::Mocks::mock_preference('item-level_itypes', 1); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot), 'noReservesAllowed', >+ "With item level set, rule from item must be picked (CANNOT)" >+ ); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can), 'OK', >+ "With item level set, rule from item must be picked (CAN)" >+ ); >+ t::lib::Mocks::mock_preference('item-level_itypes', 0); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can), 'noReservesAllowed', >+ "With biblio level set, rule from biblio must be picked (CANNOT)" >+ ); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot), 'OK', >+ "With biblio level set, rule from biblio must be picked (CAN)" >+ ); >+ }; >+ >+ subtest 'tooManyHoldsForThisRecord + tooManyReserves + itemAlreadyOnHold' => sub { >+ plan tests => 7; >+ >+ my $biblionumber_1 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; >+ my ( undef, undef, $itemnumber_11) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_1); >+ my ( undef, undef, $itemnumber_12) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_1); >+ my $biblionumber_2 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; >+ my ( undef, undef, $itemnumber_21) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_2); >+ my ( undef, undef, $itemnumber_22) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_2); >+ >+ Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; >+ >+ # Biblio-level hold >+ AddReserve( >+ $branch_1, >+ $borrowernumbers[0], >+ $biblionumber_1, >+ '', >+ 1, >+ ); >+ for my $item_level ( 0..1 ) { >+ t::lib::Mocks::mock_preference('item-level_itypes', $item_level); >+ is( >+ # FIXME This is not really correct, but CanItemBeReserved does not check if biblio-level holds already exist >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_11), 'OK', >+ "A biblio-level hold already exists - another hold can be placed on a specific item item" >+ ); >+ } >+ >+ Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; >+ # Item-level hold >+ AddReserve( >+ $branch_1, >+ $borrowernumbers[0], >+ $biblionumber_1, >+ '', >+ 1, >+ undef, undef, undef, undef, $itemnumber_11 >+ ); >+ $dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=1}); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'tooManyHoldsForThisRecord', >+ "A item-level hold already exists and holds_per_record=1, another hold cannot be placed on this record" >+ ); >+ $dbh->do(q{UPDATE issuingrules set reservesallowed=1, holds_per_record=1}); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'tooManyHoldsForThisRecord', >+ "A item-level hold already exists and holds_per_record=1 - tooManyHoldsForThisRecord has priority over tooManyReserves" >+ ); >+ $dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=2}); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'OK', >+ "A item-level hold already exists but holds_per_record=2- another item-level hold can be placed on this record" >+ ); >+ >+ AddReserve( >+ $branch_1, >+ $borrowernumbers[0], >+ $biblionumber_2, >+ '', >+ 1, >+ undef, undef, undef, undef, $itemnumber_21 >+ ); >+ $dbh->do(q{UPDATE issuingrules set reservesallowed=2, holds_per_record=2}); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_21), 'itemAlreadyOnHold', >+ "A item-level holds already exists on this item, itemAlreadyOnHold should be raised" >+ ); >+ is( >+ CanItemBeReserved( $borrowernumbers[0], $itemnumber_22), 'tooManyReserves', >+ "This patron has already placed reservesallowed holds, tooManyReserves should be raised" >+ ); >+ }; >+}; > > > # Test branch item rules > >-$dbh->do('DELETE FROM issuingrules'); >+delete_all_rules(); > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) > VALUES (?, ?, ?, ?)}, > {}, > '*', '*', '*', 25 > ); >-$dbh->do('DELETE FROM branch_item_rules'); >-$dbh->do('DELETE FROM default_branch_circ_rules'); >-$dbh->do('DELETE FROM default_branch_item_rules'); >-$dbh->do('DELETE FROM default_circ_rules'); > $dbh->do(q{ > INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch) > VALUES (?, ?, ?, ?) >@@ -675,3 +769,12 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+sub delete_all_rules { >+ my $dbh = C4::Context->dbh; >+ $dbh->do('DELETE FROM issuingrules'); >+ $dbh->do('DELETE FROM branch_item_rules'); >+ $dbh->do('DELETE FROM default_branch_circ_rules'); >+ $dbh->do('DELETE FROM default_branch_item_rules'); >+ $dbh->do('DELETE FROM default_circ_rules'); >+} >-- >2.11.0
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 16787
:
52652
|
68894
|
68895
|
72827
|
72828
|
72889
|
91146
|
91147
|
91148
|
91149
|
96152
|
97403
|
99949
|
99950
|
100951
|
101473
|
101474
|
101475
|
101895
|
107793
|
107794
|
107795
|
114675
|
114676
|
114677
|
119279
|
119280
|
119281
|
119335
|
119336
|
119337
|
119616
|
119617
|
119619
|
119620
|
119621
|
119622
|
119623
|
119738
|
119739
|
119740
|
119741
|
119942
|
120009