use Modern::Perl;
-use Test::More tests => 72;
+use Test::More tests => 59;
use Test::MockModule;
use Test::Warn;
use MARC::Record;
use DateTime::Duration;
-use C4::Biblio;
use C4::Circulation;
use C4::Items;
+use C4::Biblio;
use C4::Members;
use C4::Reserves;
+use Koha::Caches;
use Koha::DateUtils;
use Koha::Holds;
+use Koha::Items;
use Koha::Libraries;
+use Koha::Notice::Templates;
+use Koha::Patrons;
use Koha::Patron::Categories;
BEGIN {
my $builder = t::lib::TestBuilder->new;
+my $frameworkcode = q//;
+
+
+t::lib::Mocks::mock_preference('ReservesNeedReturns', 1);
+
# Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
-$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a'");
+$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a' and frameworkcode=?", undef, $frameworkcode);
+my $cache = Koha::Caches->get_instance;
+$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
+$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+$cache->clear_from_cache("default_value_for_mod_marc-");
+$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
## Setup Test
# Add branches
my $itemtype = $builder->build(
{ source => 'Itemtype', value => { notforloan => undef } } )->{itemtype};
-C4::Context->set_userenv(
- undef, undef, undef, undef, undef, undef, $branch_1
-);
+t::lib::Mocks::mock_userenv({ branchcode => $branch_1 });
-# Create a helper biblio
-my $bib = MARC::Record->new();
-my $title = 'Silence in the library';
-if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
- $bib->append_fields(
- MARC::Field->new('600', '', '1', a => 'Moffat, Steven'),
- MARC::Field->new('200', '', '', a => $title),
- );
-}
-else {
- $bib->append_fields(
- MARC::Field->new('100', '', '', a => 'Moffat, Steven'),
- MARC::Field->new('245', '', '', a => $title),
- );
-}
-my ($bibnum, $bibitemnum);
-($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
+my $bibnum = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
# Create a helper item instance for testing
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
$bibnum
);
+my $biblio_with_no_item = $builder->build({
+ source => 'Biblio'
+});
+
# Modify item; setting barcode.
my $testbarcode = '97531';
branchcode => $branch_1,
);
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
-my $borrowernumber = AddMember(%data);
-my $borrower = GetMember( borrowernumber => $borrowernumber );
+my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber;
+my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
my $biblionumber = $bibnum;
my $barcode = $testbarcode;
AddReserve($branchcode, $borrowernumber, $biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
### Regression test for bug 10272
###
my %requesters = ();
-$requesters{$branch_1} = AddMember(
+$requesters{$branch_1} = Koha::Patron->new({
branchcode => $branch_1,
categorycode => $category_2,
surname => "borrower from $branch_1",
-);
+})->store->borrowernumber;
for my $i ( 2 .. 5 ) {
- $requesters{"CPL$i"} = AddMember(
+ $requesters{"CPL$i"} = Koha::Patron->new({
branchcode => $branch_1,
categorycode => $category_2,
surname => "borrower $i from $branch_1",
- );
+ })->store->borrowernumber;
}
-$requesters{$branch_2} = AddMember(
+$requesters{$branch_2} = Koha::Patron->new({
branchcode => $branch_2,
categorycode => $category_2,
surname => "borrower from $branch_2",
-);
-$requesters{$branch_3} = AddMember(
+})->store->borrowernumber;
+$requesters{$branch_3} = Koha::Patron->new({
branchcode => $branch_3,
categorycode => $category_2,
surname => "borrower from $branch_3",
-);
+})->store->borrowernumber;
# Configure rules so that $branch_1 allows only $branch_1 patrons
# to request its items, while $branch_2 will allow its items
$dbh->do('DELETE FROM issuingrules');
$dbh->do('DELETE FROM branch_item_rules');
-$dbh->do('DELETE FROM branch_borrower_circ_rules');
-$dbh->do('DELETE FROM default_borrower_circ_rules');
$dbh->do('DELETE FROM default_branch_item_rules');
$dbh->do('DELETE FROM default_branch_circ_rules');
$dbh->do('DELETE FROM default_circ_rules');
# CPL allows only its own patrons to request its items
$dbh->do(
- q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
- VALUES (?, ?, ?, ?)},
+ q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
+ VALUES (?, ?, ?)},
{},
- $branch_1, 10, 1, 'homebranch',
+ $branch_1, 1, 'homebranch',
);
# ... while FPL allows anybody to request its items
$dbh->do(
- q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
- VALUES (?, ?, ?, ?)},
+ q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch)
+ VALUES (?, ?, ?)},
{},
- $branch_2, 10, 2, 'homebranch',
+ $branch_2, 2, 'homebranch',
);
-# helper biblio for the bug 10272 regression test
-my $bib2 = MARC::Record->new();
-$bib2->append_fields(
- MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
- MARC::Field->new('245', ' ', ' ', a => $title),
-);
+my $bibnum2 = $builder->build_sample_biblio({frameworkcode => $frameworkcode})->biblionumber;
-# create one item belonging to FPL and one belonging to CPL
-my ($bibnum2, $bibitemnum2) = AddBiblio($bib, '');
my ($itemnum_cpl, $itemnum_fpl);
( undef, undef, $itemnum_cpl ) = AddItem(
{ homebranch => $branch_1,
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
AddReserve($branch_3, $requesters{$branch_3}, $bibnum2,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
AddReserve($branch_2, $requesters{$branch_2}, $bibnum2,
$bibitems, 2, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
AddReserve($branch_1, $requesters{$branch_1}, $bibnum2,
$bibitems, 3, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
# Now it should have different priorities.
-my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2});
-# Sort by reserve number in case the database gives us oddly ordered results
-my @reserves = sort { $a->{reserve_id} <=> $b->{reserve_id} } @$title_reserves;
-is($reserves[0]{priority}, 0, 'Item is correctly waiting');
-is($reserves[1]{priority}, 1, 'Item is correctly priority 1');
-is($reserves[2]{priority}, 2, 'Item is correctly priority 2');
-
-@reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
+my $biblio = Koha::Biblios->find( $bibnum2 );
+my $holds = $biblio->holds({}, { order_by => 'reserve_id' });;
+is($holds->next->priority, 0, 'Item is correctly waiting');
+is($holds->next->priority, 1, 'Item is correctly priority 1');
+is($holds->next->priority, 2, 'Item is correctly priority 2');
+
+my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
AddReserve($branch_3, $requesters{$branch_3}, $bibnum2,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
AddReserve($branch_2, $requesters{$branch_2}, $bibnum2,
$bibitems, 2, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
AddReserve($branch_1, $requesters{$branch_1}, $bibnum2,
$bibitems, 3, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
# Ensure that the item's home library controls hold policy lookup
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
$requesters{$branch_3},
'for generous library, its items fill first hold request in line (bug 10272)');
-my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber});
-isa_ok($reserves, 'ARRAY');
-is(scalar @$reserves, 1, "Only one reserves for this biblio");
-my $reserve_id = $reserves->[0]->{reserve_id};
-
-$reserve = GetReserve($reserve_id);
-isa_ok($reserve, 'HASH', "GetReserve return");
-is($reserve->{biblionumber}, $biblionumber);
-
-$reserve = CancelReserve({reserve_id => $reserve_id});
-isa_ok($reserve, 'HASH', "CancelReserve return");
-is($reserve->{biblionumber}, $biblionumber);
-
-$reserve = GetReserve($reserve_id);
-is($reserve, undef, "GetReserve returns undef after deletion");
-
-$reserve = CancelReserve({reserve_id => $reserve_id});
-is($reserve, undef, "CancelReserve return undef if reserve does not exist");
-
+$biblio = Koha::Biblios->find( $biblionumber );
+$holds = $biblio->holds;
+is($holds->count, 1, "Only one reserves for this biblio");
+my $reserve_id = $holds->next->reserve_id;
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
($status)=CheckReserves($itemnumber,undef,undef);
is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
($status)=CheckReserves($itemnumber,undef,7);
$expdate= undef; #no expdate
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
($status)=CheckReserves($itemnumber,undef,undef);
is( $status, '', 'CheckReserves returns no future reserve without lookahead');
'item that is captured to fill a hold cannot be deleted',
);
-my $letter = ReserveSlip($branch_1, $requesters{$branch_1}, $bibnum);
+my $letter = ReserveSlip( { branchcode => $branch_1, borrowernumber => $requesters{$branch_1}, biblionumber => $bibnum } );
ok(defined($letter), 'can successfully generate hold slip (bug 10949)');
-# Tests for bug 9788: Does GetReservesFromItemnumber return a future wait?
-# 9788a: GetReservesFromItemnumber does not return future next available hold
+# Tests for bug 9788: Does Koha::Item->current_holds return a future wait?
+# 9788a: current_holds does not return future next available hold
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
$resdate=output_pref($resdate);
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
-my @results= GetReservesFromItemnumber($itemnumber);
-is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future next available hold');
-# 9788b: GetReservesFromItemnumber does not return future item level hold
+ 'a title', $checkitem, $found);
+my $item = Koha::Items->find( $itemnumber );
+$holds = $item->current_holds;
+my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+my $future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
+is( $future_holds->count, 0, 'current_holds does not return a future next available hold');
+# 9788b: current_holds does not return future item level hold
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $itemnumber, $found); #item level hold
-@results= GetReservesFromItemnumber($itemnumber);
-is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future item level hold');
-# 9788c: GetReservesFromItemnumber returns future wait (confirmed future hold)
+ 'a title', $itemnumber, $found); #item level hold
+$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
+is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
+# 9788c: current_holds returns future wait (confirmed future hold)
ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0); #confirm hold
-@results= GetReservesFromItemnumber($itemnumber);
-is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
+$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
+is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
# End of tests for bug 9788
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
$resdate=undef;
AddReserve($branch_1, $requesters{'CPL2'}, $bibnum2,
$bibitems, $p, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
$p = C4::Reserves::CalculatePriority($bibnum2);
is($p, 5, 'CalculatePriority should now return priority 5');
#some tests on bibnum
#add a new reserve and confirm it to waiting
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, $p, $resdate, $expdate, $notes,
- $title, $itemnumber, $found);
+ 'a title', $itemnumber, $found);
$p = C4::Reserves::CalculatePriority($bibnum);
is($p, 2, 'CalculatePriority should now return priority 2');
ModReserveAffect( $itemnumber, $requesters{$branch_1} , 0);
#add another biblio hold, no resdate
AddReserve($branch_1, $requesters{'CPL2'}, $bibnum,
$bibitems, $p, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
$p = C4::Reserves::CalculatePriority($bibnum);
is($p, 2, 'CalculatePriority should now return priority 2');
#add another future hold
$resdate->add_duration(DateTime::Duration->new(days => 1));
AddReserve($branch_1, $requesters{'CPL3'}, $bibnum,
$bibitems, $p, output_pref($resdate), $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
$p = C4::Reserves::CalculatePriority($bibnum);
is($p, 2, 'CalculatePriority should now still return priority 2');
#calc priority with future resdate
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum,
$bibitems, 1, undef, $expdate, $notes,
- $title, $checkitem, '');
+ 'a title', $checkitem, '');
my (undef, $canres, undef) = CheckReserves($itemnumber);
is( CanReserveBeCanceledFromOpac(), undef,
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum,
$bibitems, 1, undef, $expdate, $notes,
- $title, $checkitem, '');
+ 'a title', $checkitem, '');
(undef, $canres, undef) = CheckReserves($itemnumber);
ModReserveAffect($itemnumber, $requesters{$branch_1}, 0);
#Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
#Set the ageRestriction for the Biblio
-my $record = GetMarcBiblio( $bibnum );
+my $record = GetMarcBiblio({ biblionumber => $bibnum });
my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
$record->append_fields( MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16') );
-C4::Biblio::ModBiblio( $record, $bibnum, '' );
+C4::Biblio::ModBiblio( $record, $bibnum, $frameworkcode );
+
+is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'OK', "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
-is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
+#Set the dateofbirth for the Borrower making them "too young".
+$borrower->{dateofbirth} = DateTime->now->add( years => -15 );
+Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
-#Set the dateofbirth for the Borrower making him "too young".
-my $now = DateTime->now();
-C4::Members::SetAge( $borrower, '0015-00-00' );
-C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
+is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
-is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
+#Set the dateofbirth for the Borrower making them "too old".
+$borrower->{dateofbirth} = DateTime->now->add( years => -30 );
+Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
-#Set the dateofbirth for the Borrower making him "too old".
-C4::Members::SetAge( $borrower, '0030-00-00' );
-C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
+is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
-is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
+is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{biblionumber})->{status} , '', "Biblio with no item. Status is empty");
####
####### EO Bug 13113 <<<
####
-my $item = GetItem($itemnumber);
+$item = Koha::Items->find($itemnumber)->unblessed;
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
-my $itype = C4::Reserves::_get_itype($item);
-my $categorycode = $borrower->{categorycode};
-my $holdingbranch = $item->{holdingbranch};
-my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
+my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
+t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
+t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
+my ($item_object) = Koha::Biblios->find($biblionumber)->items;
+my $limit = Koha::Item::Transfer::Limit->new(
{
- categorycode => $categorycode,
- itemtype => $itype,
- branchcode => $holdingbranch
+ toBranch => $pickup_branch,
+ fromBranch => $item_object->holdingbranch,
+ itemtype => $item_object->effective_itemtype,
}
-);
-
-$dbh->do(
- "UPDATE issuingrules SET onshelfholds = 1 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
- undef,
- $issuing_rule->categorycode, $issuing_rule->itemtype, $issuing_rule->branchcode
-);
-ok( C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() allowed" );
-$dbh->do(
- "UPDATE issuingrules SET onshelfholds = 0 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
- undef,
- $issuing_rule->categorycode, $issuing_rule->itemtype, $issuing_rule->branchcode
-);
-ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" );
-
-# Tests for bug 14464
-
-$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
-my ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
-is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
-
-# First, test cancelling a reserve when there's no charge configured.
-t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
-
-my $bz14464_reserve = AddReserve(
- $branch_1,
- $borrowernumber,
- $bibnum,
- undef,
- '1',
- undef,
- undef,
- '',
- $title,
- $itemnumber,
- 'W'
-);
-
-ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
-
-CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
-
-my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
-is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
-
-( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
-is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
-
-# Then, test cancelling a reserve when there's no charge desired.
-t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
-
-$bz14464_reserve = AddReserve(
- $branch_1,
- $borrowernumber,
- $bibnum,
- undef,
- '1',
- undef,
- undef,
- '',
- $title,
- $itemnumber,
- 'W'
-);
-
-ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' );
-
-CancelReserve({ reserve_id => $bz14464_reserve });
-
-( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
-is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
-
-# Finally, test cancelling a reserve when there's a charge desired and configured.
-$bz14464_reserve = AddReserve(
- $branch_1,
- $borrowernumber,
- $bibnum,
- undef,
- '1',
- undef,
- undef,
- '',
- $title,
- $itemnumber,
- 'W'
-);
-
-ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
-
-CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
-
-( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
-is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
+)->store();
+is( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower, $pickup_branch), 0, "Item level request not available due to transfer limit" );
+t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
# hold from A pos 1, today, no fut holds: MoveReserve should fill it
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 0);
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, undef, $expdate, $notes, $title, $checkitem, '');
+ $bibitems, 1, undef, $expdate, $notes, 'a title', $checkitem, '');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber );
is( $status, '', 'MoveReserve filled hold');
# hold from A waiting, today, no fut holds: MoveReserve should fill it
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, undef, $expdate, $notes, $title, $checkitem, 'W');
+ $bibitems, 1, undef, $expdate, $notes, 'a title', $checkitem, 'W');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber );
is( $status, '', 'MoveReserve filled waiting hold');
$resdate->add_duration(DateTime::Duration->new(days => 1));
$resdate=output_pref($resdate);
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, '');
+ $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber, undef, 1 );
is( $status, 'Reserved', 'MoveReserve did not fill future hold');
# hold from A pos 1, tomorrow, fut holds=2: MoveReserve should fill it
t::lib::Mocks::mock_preference('ConfirmFutureHolds', 2);
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, '');
+ $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber, undef, 2 );
is( $status, '', 'MoveReserve filled future hold now');
# hold from A waiting, tomorrow, fut holds=2: MoveReserve should fill it
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, 'W');
+ $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, 'W');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber, undef, 2 );
is( $status, '', 'MoveReserve filled future waiting hold now');
$resdate->add_duration(DateTime::Duration->new(days => 3));
$resdate=output_pref($resdate);
AddReserve($branch_1, $borrowernumber, $item_bibnum,
- $bibitems, 1, $resdate, $expdate, $notes, $title, $checkitem, '');
+ $bibitems, 1, $resdate, $expdate, $notes, 'a title', $checkitem, '');
MoveReserve( $itemnumber, $borrowernumber );
($status)=CheckReserves( $itemnumber, undef, 3 );
is( $status, 'Reserved', 'MoveReserve did not fill future hold of 3 days');
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
-# we reached the finish
-$schema->storage->txn_rollback();
+$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
+$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+$cache->clear_from_cache("default_value_for_mod_marc-");
+$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
+
+subtest '_koha_notify_reserve() tests' => sub {
+
+ plan tests => 2;
+
+ my $wants_hold_and_email = {
+ wants_digest => '0',
+ transports => {
+ sms => 'HOLD',
+ email => 'HOLD',
+ },
+ letter_code => 'HOLD'
+ };
+
+ my $mp = Test::MockModule->new( 'C4::Members::Messaging' );
+
+ $mp->mock("GetMessagingPreferences",$wants_hold_and_email);
+
+ $dbh->do('DELETE FROM letter');
+
+ my $email_hold_notice = $builder->build({
+ source => 'Letter',
+ value => {
+ message_transport_type => 'email',
+ branchcode => '',
+ code => 'HOLD',
+ module => 'reserves',
+ lang => 'default',
+ }
+ });
+
+ my $sms_hold_notice = $builder->build({
+ source => 'Letter',
+ value => {
+ message_transport_type => 'sms',
+ branchcode => '',
+ code => 'HOLD',
+ module => 'reserves',
+ lang=>'default',
+ }
+ });
+
+ my $hold_borrower = $builder->build({
+ source => 'Borrower',
+ value => {
+ smsalertnumber=>'5555555555',
+ email=>'a@b.com',
+ }
+ })->{borrowernumber};
+
+ C4::Reserves::AddReserve(
+ $item->{homebranch}, $hold_borrower,
+ $item->{biblionumber} );
+
+ ModReserveAffect($item->{itemnumber}, $hold_borrower, 0);
+ my $sms_message_address = $schema->resultset('MessageQueue')->search({
+ letter_code => 'HOLD',
+ message_transport_type => 'sms',
+ borrowernumber => $hold_borrower,
+ })->next()->to_address();
+ is($sms_message_address, undef ,"We should not populate the sms message with the sms number, sending will do so");
+
+ my $email_message_address = $schema->resultset('MessageQueue')->search({
+ letter_code => 'HOLD',
+ message_transport_type => 'email',
+ borrowernumber => $hold_borrower,
+ })->next()->to_address();
+ is($email_message_address, undef ,"We should not populate the hold message with the email address, sending will do so");
+
+};
+
+subtest 'ReservesNeedReturns' => sub {
+ plan tests => 4;
+
+ my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
+ my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } );
+ my $item_info = {
+ biblionumber => $biblioitem->biblionumber,
+ biblioitemnumber => $biblioitem->biblioitemnumber,
+ homebranch => $library->branchcode,
+ holdingbranch => $library->branchcode,
+ itype => $itemtype->itemtype,
+ };
+ my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } );
+ my $patron = $builder->build_object(
+ {
+ class => 'Koha::Patrons',
+ value => { branchcode => $library->branchcode, }
+ }
+ );
+
+ my $priority = 1;
+ my ( $hold_id, $hold );
+
+ t::lib::Mocks::mock_preference('ReservesNeedReturns', 0); # '0' means 'Automatically mark a hold as found and waiting'
+ $hold_id = C4::Reserves::AddReserve(
+ $library->branchcode, $patron->borrowernumber,
+ $item->biblionumber, '',
+ $priority, undef,
+ undef, '',
+ "title for fee", $item->itemnumber,
+ );
+ $hold = Koha::Holds->find($hold_id);
+ is( $hold->priority, 0, 'If ReservesNeedReturns is 0, priority must have been set to 0' );
+ is( $hold->found, 'W', 'If ReservesNeedReturns is 0, found must have been set waiting' );
+
+ $hold->delete; # cleanup
+
+ t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # '0' means "Don't automatically mark a hold as found and waiting"
+ $hold_id = C4::Reserves::AddReserve(
+ $library->branchcode, $patron->borrowernumber,
+ $item->biblionumber, '',
+ $priority, undef,
+ undef, '',
+ "title for fee", $item->itemnumber,
+ );
+ $hold = Koha::Holds->find($hold_id);
+ is( $hold->priority, $priority, 'If ReservesNeedReturns is 1, priority must not have been set to changed' );
+ is( $hold->found, undef, 'If ReservesNeedReturns is 1, found must not have been set waiting' );
+};
+
+subtest 'ChargeReserveFee tests' => sub {
+
+ plan tests => 8;
+
+ my $library = $builder->build_object({ class => 'Koha::Libraries' });
+ my $patron = $builder->build_object({ class => 'Koha::Patrons' });
+
+ my $fee = 20;
+ my $title = 'A title';
+
+ my $context = Test::MockModule->new('C4::Context');
+ $context->mock( userenv => { branch => $library->id } );
+
+ my $line = C4::Reserves::ChargeReserveFee( $patron->id, $fee, $title );
+
+ is( ref($line), 'Koha::Account::Line' , 'Returns a Koha::Account::Line object');
+ ok( $line->is_debit, 'Generates a debit line' );
+ is( $line->accounttype, 'Res' , 'generates Res accounttype');
+ is( $line->borrowernumber, $patron->id , 'generated line belongs to the passed patron');
+ is( $line->amount, $fee , 'amount set correctly');
+ is( $line->amountoutstanding, $fee , 'amountoutstanding set correctly');
+ is( $line->description, "Reserve Charge - $title" , 'Hardcoded description is generated');
+ is( $line->branchcode, $library->id , "Library id is picked from userenv and stored correctly" );
+};
sub count_hold_print_messages {
my $message_count = $dbh->selectall_arrayref(q{
});
return $message_count->[0]->[0];
}
+
+# we reached the finish
+$schema->storage->txn_rollback();