use Modern::Perl;
-use Test::More tests => 71;
+use Test::More tests => 72;
use Test::MockModule;
use Test::Warn;
use Koha::DateUtils;
use Koha::Holds;
use Koha::Libraries;
+use Koha::Notice::Templates;
+use Koha::Patrons;
use Koha::Patron::Categories;
BEGIN {
MARC::Field->new('245', '', '', a => $title),
);
}
-my ($bibnum, $bibitemnum);
-($bibnum, $title, $bibitemnum) = AddBiblio($bib, $frameworkcode);
+my ( $bibnum ) = AddBiblio($bib, $frameworkcode);
# Create a helper item instance for testing
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
);
Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store;
my $borrowernumber = AddMember(%data);
-my $borrower = GetMember( borrowernumber => $borrowernumber );
+my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
my $biblionumber = $bibnum;
my $barcode = $testbarcode;
);
# create one item belonging to FPL and one belonging to CPL
-my ($bibnum2, $bibitemnum2) = AddBiblio($bib, $frameworkcode);
+my ( $bibnum2 ) = AddBiblio($bib, $frameworkcode);
my ($itemnum_cpl, $itemnum_fpl);
( undef, undef, $itemnum_cpl ) = AddItem(
{ homebranch => $branch_1,
my $letter = ReserveSlip($branch_1, $requesters{$branch_1}, $bibnum);
ok(defined($letter), 'can successfully generate hold slip (bug 10949)');
-# Tests for bug 9788: Does Koha::Item->holds_placed_before_today return a future wait?
-# 9788a: holds_placed_before_today 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);
$bibitems, 1, $resdate, $expdate, $notes,
$title, $checkitem, $found);
my $item = Koha::Items->find( $itemnumber );
-$holds = $item->holds_placed_before_today;
+$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, 'holds_placed_before_today does not return a future next available hold');
-# 9788b: holds_placed_before_today does not return future item level hold
+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
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
-is( $future_holds->count, 0, 'holds_placed_before_today does not return a future item level hold' );
-# 9788c: holds_placed_before_today returns future wait (confirmed future hold)
+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
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
-is( $future_holds->count, 1, 'holds_placed_before_today returns a future wait (confirmed future hold)' );
+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));
#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, $frameworkcode );
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
-#Set the dateofbirth for the Borrower making him "too young".
+#Set the dateofbirth for the Borrower making them "too young".
$borrower->{dateofbirth} = DateTime->now->add( years => -15 );
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
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 him "too old".
+#Set the dateofbirth for the Borrower making them "too old".
$borrower->{dateofbirth} = DateTime->now->add( years => -30 );
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
$cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
-# we reached the finish
-$schema->storage->txn_rollback();
+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};
+
+ my $hold = $builder->build({
+ source => 'Reserve',
+ value => {
+ borrowernumber=>$hold_borrower
+ }
+ });
+
+ ModReserveAffect($hold->{itemnumber}, $hold->{borrowernumber}, 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");
+
+};
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();