+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" );
+};
+