use Modern::Perl;
-use Test::More tests => 6;
+use Test::More tests => 2;
use Test::MockModule;
use t::lib::TestBuilder;
use t::lib::Mocks;
my $res1 = addreserve( $patron1->{borrowernumber} );
is( acctlines( $patron1->{borrowernumber} ), $acc1, 'No fee charged for patron 1' );
-# Issue item1 to patron1. Since there is still a reserve too, we should
-# expect a charge for patron2.
-C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
-my $acc2 = acctlines( $patron2->{borrowernumber} );
-t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
-my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
-is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
-C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->{title} );
-is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
-
-# If we delete the reserve, there should be no charge
-$dbh->do( "DELETE FROM reserves WHERE reserve_id=?", undef, ( $res1 ) );
-$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
-is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
-
-t::lib::Mocks::mock_preference('HoldFeeMode', 'always');
-$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
-is( int($fee), 2, 'HoldFeeMode=always, Patron 2 should be charged' );
-
-# If we delete the second item, there should be a charge
-$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, ( $item2->{itemnumber} ) );
-$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
-is( int($fee), 2, 'Patron 2 should be charged again this time' );
-# End of tests
+subtest 'GetReserveFee' => sub {
+ plan tests => 7;
+
+ # Issue item1 to patron1. Since there is still a reserve too, we should
+ # expect a charge for patron2.
+ C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter
+ my $acc2 = acctlines( $patron2->{borrowernumber} );
+
+ t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always');
+ my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' );
+ C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->{title} );
+ is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' );
+
+ # If we delete the reserve, there should be no charge
+ $dbh->do( "DELETE FROM reserves WHERE reserve_id=?", undef, ( $res1 ) );
+ $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' );
+
+ t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
+ $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' );
+
+ t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
+ $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
+
+ # If we delete the second item, there should be a charge
+ t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed');
+ $dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, ( $item2->{itemnumber} ) );
+ $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( int($fee), 2, 'Patron 2 should be charged again this time' );
+
+ t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected');
+ $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} );
+ is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' );
+};
sub acctlines { #calculate number of accountlines for a patron
my @temp = $dbh->selectrow_array( "SELECT COUNT(*) FROM accountlines WHERE borrowernumber=?", undef, ( $_[0] ) );