|
Lines 6-16
use Test::More tests => 16;
Link Here
|
| 6 |
use C4::Context; |
6 |
use C4::Context; |
| 7 |
use Koha::Database; |
7 |
use Koha::Database; |
| 8 |
use Koha::Libraries; |
8 |
use Koha::Libraries; |
|
|
9 |
|
| 10 |
use t::lib::Mocks; |
| 11 |
use t::lib::TestBuilder; |
| 12 |
|
| 9 |
use_ok('C4::Overdues'); |
13 |
use_ok('C4::Overdues'); |
| 10 |
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes'); |
14 |
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes'); |
| 11 |
can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules'); |
15 |
can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules'); |
| 12 |
|
16 |
|
| 13 |
my $schema = Koha::Database->new->schema; |
17 |
my $schema = Koha::Database->new->schema; |
|
|
18 |
my $builder = t::lib::TestBuilder->new; |
| 19 |
|
| 14 |
$schema->storage->txn_begin; |
20 |
$schema->storage->txn_begin; |
| 15 |
my $dbh = C4::Context->dbh; |
21 |
my $dbh = C4::Context->dbh; |
| 16 |
|
22 |
|
|
Lines 121-123
$dbh->do(q|
Link Here
|
| 121 |
|
127 |
|
| 122 |
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); |
128 |
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); |
| 123 |
is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' ); |
129 |
is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' ); |
| 124 |
- |
130 |
|
|
|
131 |
$schema->storage->txn_rollback; |
| 132 |
|
| 133 |
subtest 'UpdateFine tests' => sub { |
| 134 |
|
| 135 |
plan tests => 8; |
| 136 |
|
| 137 |
$schema->storage->txn_begin; |
| 138 |
|
| 139 |
t::lib::Mocks::mock_preference( 'MaxFine', '100' ); |
| 140 |
|
| 141 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 142 |
my $item1 = $builder->build_sample_item(); |
| 143 |
my $item2 = $builder->build_sample_item(); |
| 144 |
my $checkout1 = $builder->build_object( |
| 145 |
{ |
| 146 |
class => 'Koha::Checkouts', |
| 147 |
value => { itemnumber => $item1->itemnumber } |
| 148 |
} |
| 149 |
); |
| 150 |
my $checkout2 = $builder->build_object( |
| 151 |
{ |
| 152 |
class => 'Koha::Checkouts', |
| 153 |
value => { itemnumber => $item2->itemnumber } |
| 154 |
} |
| 155 |
); |
| 156 |
|
| 157 |
UpdateFine( |
| 158 |
{ |
| 159 |
issue_id => $checkout1->issue_id, |
| 160 |
itemnumber => $item1->itemnumber, |
| 161 |
borrowernumber => $patron->borrowernumber, |
| 162 |
amount => '0', |
| 163 |
due => $checkout1->date_due |
| 164 |
} |
| 165 |
); |
| 166 |
|
| 167 |
my $fines = Koha::Account::Lines->search( |
| 168 |
{ borrowernumber => $patron->borrowernumber } ); |
| 169 |
is( $fines->count, 0, "No fine added when amount is 0" ); |
| 170 |
|
| 171 |
UpdateFine( |
| 172 |
{ |
| 173 |
issue_id => $checkout1->issue_id, |
| 174 |
itemnumber => $item1->itemnumber, |
| 175 |
borrowernumber => $patron->borrowernumber, |
| 176 |
amount => '50', |
| 177 |
due => $checkout1->date_due |
| 178 |
} |
| 179 |
); |
| 180 |
|
| 181 |
$fines = Koha::Account::Lines->search( |
| 182 |
{ borrowernumber => $patron->borrowernumber } ); |
| 183 |
is( $fines->count, 1, "Fine added when amount is greater than 0" ); |
| 184 |
my $fine = $fines->next; |
| 185 |
is( $fine->amount, '50', "Fine amount correctly set to 50" ); |
| 186 |
|
| 187 |
UpdateFine( |
| 188 |
{ |
| 189 |
issue_id => $checkout1->issue_id, |
| 190 |
itemnumber => $item1->itemnumber, |
| 191 |
borrowernumber => $patron->borrowernumber, |
| 192 |
amount => '80', |
| 193 |
due => $checkout1->date_due |
| 194 |
} |
| 195 |
); |
| 196 |
|
| 197 |
$fines = Koha::Account::Lines->search( |
| 198 |
{ borrowernumber => $patron->borrowernumber } ); |
| 199 |
is( $fines->count, 1, "Existing fine updated" ); |
| 200 |
$fine = $fines->next; |
| 201 |
is( $fine->amount, '80', "Fine amount correctly updated to 80" ); |
| 202 |
|
| 203 |
UpdateFine( |
| 204 |
{ |
| 205 |
issue_id => $checkout2->issue_id, |
| 206 |
itemnumber => $item2->itemnumber, |
| 207 |
borrowernumber => $patron->borrowernumber, |
| 208 |
amount => '30', |
| 209 |
due => $checkout2->date_due |
| 210 |
} |
| 211 |
); |
| 212 |
|
| 213 |
$fines = Koha::Account::Lines->search( |
| 214 |
{ borrowernumber => $patron->borrowernumber }, |
| 215 |
{ order_by => { 'ASC' => 'accountlines_id' } } |
| 216 |
); |
| 217 |
is( $fines->count, 2, "New fine added for second checkout" ); |
| 218 |
is( $fines->next->amount, '80', "First fine amount unchanged" ); |
| 219 |
is( $fines->next->amount, '20', "Second fine capped at '20' by MaxFine" ); |
| 220 |
|
| 221 |
$schema->storage->txn_rollback; |
| 222 |
}; |