use Modern::Perl;
-use Test::More tests => 72;
+use Test::More tests => 73;
use Test::MockModule;
use Test::Warn;
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' and frameworkcode=?", undef, $frameworkcode);
my $cache = Koha::Caches->get_instance;
};
+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' );
+};
+
sub count_hold_print_messages {
my $message_count = $dbh->selectall_arrayref(q{
SELECT COUNT(*)