|
Lines 21-32
use Modern::Perl;
Link Here
|
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 11; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
|
|
24 |
use Test::MockModule; |
| 25 |
|
| 26 |
use DateTime; |
| 24 |
|
27 |
|
| 25 |
use C4::Circulation qw/AddIssue AddReturn/; |
28 |
use C4::Circulation qw/AddIssue AddReturn/; |
| 26 |
use Koha::Account; |
29 |
use Koha::Account; |
| 27 |
use Koha::Account::Lines; |
30 |
use Koha::Account::Lines; |
| 28 |
use Koha::Account::Offsets; |
31 |
use Koha::Account::Offsets; |
| 29 |
use Koha::Items; |
32 |
use Koha::Items; |
|
|
33 |
use Koha::DateUtils qw( dt_from_string ); |
| 30 |
|
34 |
|
| 31 |
use t::lib::Mocks; |
35 |
use t::lib::Mocks; |
| 32 |
use t::lib::TestBuilder; |
36 |
use t::lib::TestBuilder; |
|
Lines 132-138
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
| 132 |
|
136 |
|
| 133 |
subtest 'apply() tests' => sub { |
137 |
subtest 'apply() tests' => sub { |
| 134 |
|
138 |
|
| 135 |
plan tests => 24; |
139 |
plan tests => 25; |
| 136 |
|
140 |
|
| 137 |
$schema->storage->txn_begin; |
141 |
$schema->storage->txn_begin; |
| 138 |
|
142 |
|
|
Lines 243-248
subtest 'apply() tests' => sub {
Link Here
|
| 243 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
247 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
| 244 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
248 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
| 245 |
|
249 |
|
|
|
250 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 251 |
my $biblio = $builder->build_sample_biblio(); |
| 252 |
my $item = |
| 253 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 254 |
my $now = dt_from_string(); |
| 255 |
my $seven_weeks = DateTime::Duration->new(weeks => 7); |
| 256 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
| 257 |
my $seven_weeks_ago = $now - $seven_weeks; |
| 258 |
my $five_weeks_ago = $now - $five_weeks; |
| 259 |
|
| 260 |
my $checkout = Koha::Checkout->new( |
| 261 |
{ |
| 262 |
borrowernumber => $patron->id, |
| 263 |
itemnumber => $item->id, |
| 264 |
date_due => $five_weeks_ago, |
| 265 |
branchcode => $library->id, |
| 266 |
issuedate => $seven_weeks_ago |
| 267 |
} |
| 268 |
)->store(); |
| 269 |
|
| 270 |
my $accountline = Koha::Account::Line->new( |
| 271 |
{ |
| 272 |
issue_id => $checkout->id, |
| 273 |
borrowernumber => $patron->id, |
| 274 |
itemnumber => $item->id, |
| 275 |
branchcode => $library->id, |
| 276 |
date => \'NOW()', |
| 277 |
accounttype => 'OVERDUE', |
| 278 |
status => 'UNRETURNED', |
| 279 |
interface => 'cli', |
| 280 |
amount => '1', |
| 281 |
amountoutstanding => '1', |
| 282 |
} |
| 283 |
)->store(); |
| 284 |
|
| 285 |
# Enable renewing upon fine payment |
| 286 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
| 287 |
my $called = 0; |
| 288 |
my $module = new Test::MockModule('C4::Circulation'); |
| 289 |
$module->mock('AddRenewal', sub { $called = 1; }); |
| 290 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
| 291 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id }); |
| 292 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
| 293 |
|
| 294 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
| 295 |
|
| 246 |
$schema->storage->txn_rollback; |
296 |
$schema->storage->txn_rollback; |
| 247 |
}; |
297 |
}; |
| 248 |
|
298 |
|
| 249 |
- |
|
|