use Modern::Perl;
-use Test::More tests => 57;
+use Test::More tests => 59;
use Test::MockModule;
use Test::Warn;
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 ) = AddBiblio($bib, $frameworkcode);
+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';
AddReserve($branchcode, $borrowernumber, $biblionumber,
$bibitems, $priority, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
$branch_2, 10, 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 ) = AddBiblio($bib, $frameworkcode);
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.
$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' );
$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');
$resdate=output_pref($resdate);
AddReserve($branch_1, $requesters{$branch_1}, $bibnum,
$bibitems, 1, $resdate, $expdate, $notes,
- $title, $checkitem, $found);
+ 'a title', $checkitem, $found);
my $item = Koha::Items->find( $itemnumber );
$holds = $item->current_holds;
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
$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
+ '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)
$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);
Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
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, $biblio_with_no_item->{biblionumber})->{status} , '', "Biblio with no item. Status is empty");
####
####### EO Bug 13113 <<<
####
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');
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{
SELECT COUNT(*)