Lines 21-27
Link Here
|
21 |
|
21 |
|
22 |
use Modern::Perl; |
22 |
use Modern::Perl; |
23 |
|
23 |
|
24 |
use Test::More tests => 6; |
24 |
use Test::More tests => 2; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
27 |
use t::lib::Mocks; |
27 |
use t::lib::Mocks; |
Lines 93-122
my $acc1 = acctlines( $patron1->{borrowernumber} );
Link Here
|
93 |
my $res1 = addreserve( $patron1->{borrowernumber} ); |
93 |
my $res1 = addreserve( $patron1->{borrowernumber} ); |
94 |
is( acctlines( $patron1->{borrowernumber} ), $acc1, 'No fee charged for patron 1' ); |
94 |
is( acctlines( $patron1->{borrowernumber} ), $acc1, 'No fee charged for patron 1' ); |
95 |
|
95 |
|
96 |
# Issue item1 to patron1. Since there is still a reserve too, we should |
96 |
subtest 'GetReserveFee' => sub { |
97 |
# expect a charge for patron2. |
97 |
plan tests => 7; |
98 |
C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter |
98 |
|
99 |
my $acc2 = acctlines( $patron2->{borrowernumber} ); |
99 |
# Issue item1 to patron1. Since there is still a reserve too, we should |
100 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always'); |
100 |
# expect a charge for patron2. |
101 |
my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
101 |
C4::Circulation::AddIssue( $patron1, $item1->{barcode}, '2015-12-31', 0, undef, 0, {} ); # the date does not really matter |
102 |
is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' ); |
102 |
my $acc2 = acctlines( $patron2->{borrowernumber} ); |
103 |
C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->{title} ); |
103 |
|
104 |
is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' ); |
104 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'not_always'); |
105 |
|
105 |
my $fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
106 |
# If we delete the reserve, there should be no charge |
106 |
is( $fee > 0, 1, 'Patron 2 should be charged cf GetReserveFee' ); |
107 |
$dbh->do( "DELETE FROM reserves WHERE reserve_id=?", undef, ( $res1 ) ); |
107 |
C4::Reserves::ChargeReserveFee( $patron2->{borrowernumber}, $fee, $biblio->{title} ); |
108 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
108 |
is( acctlines( $patron2->{borrowernumber} ), $acc2 + 1, 'Patron 2 has been charged by ChargeReserveFee' ); |
109 |
is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' ); |
109 |
|
110 |
|
110 |
# If we delete the reserve, there should be no charge |
111 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'always'); |
111 |
$dbh->do( "DELETE FROM reserves WHERE reserve_id=?", undef, ( $res1 ) ); |
112 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
112 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
113 |
is( int($fee), 2, 'HoldFeeMode=always, Patron 2 should be charged' ); |
113 |
is( $fee, 0, 'HoldFeeMode=not_always, Patron 2 should not be charged' ); |
114 |
|
114 |
|
115 |
# If we delete the second item, there should be a charge |
115 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed'); |
116 |
$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, ( $item2->{itemnumber} ) ); |
116 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
117 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
117 |
is( int($fee), 2, 'HoldFeeMode=any_time_is_placed, Patron 2 should be charged' ); |
118 |
is( int($fee), 2, 'Patron 2 should be charged again this time' ); |
118 |
|
119 |
# End of tests |
119 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected'); |
|
|
120 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
121 |
is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' ); |
122 |
|
123 |
# If we delete the second item, there should be a charge |
124 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_placed'); |
125 |
$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, ( $item2->{itemnumber} ) ); |
126 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
127 |
is( int($fee), 2, 'Patron 2 should be charged again this time' ); |
128 |
|
129 |
t::lib::Mocks::mock_preference('HoldFeeMode', 'any_time_is_collected'); |
130 |
$fee = C4::Reserves::GetReserveFee( $patron2->{borrowernumber}, $biblio->{biblionumber} ); |
131 |
is( int($fee), 2, 'HoldFeeMode=any_time_is_collected, Patron 2 should be charged' ); |
132 |
}; |
120 |
|
133 |
|
121 |
sub acctlines { #calculate number of accountlines for a patron |
134 |
sub acctlines { #calculate number of accountlines for a patron |
122 |
my @temp = $dbh->selectrow_array( "SELECT COUNT(*) FROM accountlines WHERE borrowernumber=?", undef, ( $_[0] ) ); |
135 |
my @temp = $dbh->selectrow_array( "SELECT COUNT(*) FROM accountlines WHERE borrowernumber=?", undef, ( $_[0] ) ); |
123 |
- |
|
|