|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
|
24 |
|
| 25 |
use Koha::Database; |
25 |
use Koha::Database; |
|
Lines 72-74
subtest 'add_guarantor() tests' => sub {
Link Here
|
| 72 |
|
72 |
|
| 73 |
$schema->storage->txn_rollback; |
73 |
$schema->storage->txn_rollback; |
| 74 |
}; |
74 |
}; |
| 75 |
- |
75 |
|
|
|
76 |
subtest 'add_enrolment_fee_if_needed() tests' => sub { |
| 77 |
|
| 78 |
plan tests => 2; |
| 79 |
|
| 80 |
subtest 'category has enrolment fee' => sub { |
| 81 |
plan tests => 7; |
| 82 |
|
| 83 |
$schema->storage->txn_begin; |
| 84 |
|
| 85 |
my $category = $builder->build_object( |
| 86 |
{ |
| 87 |
class => 'Koha::Patron::Categories', |
| 88 |
value => { |
| 89 |
enrolmentfee => 20 |
| 90 |
} |
| 91 |
} |
| 92 |
); |
| 93 |
|
| 94 |
my $patron = $builder->build_object( |
| 95 |
{ |
| 96 |
class => 'Koha::Patrons', |
| 97 |
value => { |
| 98 |
categorycode => $category->categorycode |
| 99 |
} |
| 100 |
} |
| 101 |
); |
| 102 |
|
| 103 |
my $enrollment_fee = $patron->add_enrolment_fee_if_needed(); |
| 104 |
is( $enrollment_fee * 1, 20, 'Enrolment fee amount is correct' ); |
| 105 |
my $account = $patron->account; |
| 106 |
is( $patron->account->balance * 1, 20, 'Patron charged the enrolment fee' ); |
| 107 |
# second enrolment fee, new |
| 108 |
$enrollment_fee = $patron->add_enrolment_fee_if_needed(0); |
| 109 |
# third enrolment fee, renewal |
| 110 |
$enrollment_fee = $patron->add_enrolment_fee_if_needed(1); |
| 111 |
is( $patron->account->balance * 1, 60, 'Patron charged the enrolment fees' ); |
| 112 |
|
| 113 |
my @debits = $account->outstanding_debits; |
| 114 |
is( scalar @debits, 3, '3 enrolment fees' ); |
| 115 |
is( $debits[0]->accounttype, 'ACCOUNT', 'Account type set correctly' ); |
| 116 |
is( $debits[1]->accounttype, 'ACCOUNT', 'Account type set correctly' ); |
| 117 |
is( $debits[2]->accounttype, 'ACCOUNT_RENEW', 'Account type set correctly' ); |
| 118 |
|
| 119 |
$schema->storage->txn_rollback; |
| 120 |
}; |
| 121 |
|
| 122 |
subtest 'no enrolment fee' => sub { |
| 123 |
|
| 124 |
plan tests => 3; |
| 125 |
|
| 126 |
$schema->storage->txn_begin; |
| 127 |
|
| 128 |
my $category = $builder->build_object( |
| 129 |
{ |
| 130 |
class => 'Koha::Patron::Categories', |
| 131 |
value => { |
| 132 |
enrolmentfee => 0 |
| 133 |
} |
| 134 |
} |
| 135 |
); |
| 136 |
|
| 137 |
my $patron = $builder->build_object( |
| 138 |
{ |
| 139 |
class => 'Koha::Patrons', |
| 140 |
value => { |
| 141 |
categorycode => $category->categorycode |
| 142 |
} |
| 143 |
} |
| 144 |
); |
| 145 |
|
| 146 |
my $enrollment_fee = $patron->add_enrolment_fee_if_needed(); |
| 147 |
is( $enrollment_fee * 1, 0, 'No enrolment fee' ); |
| 148 |
my $account = $patron->account; |
| 149 |
is( $patron->account->balance, 0, 'Patron not charged anything' ); |
| 150 |
|
| 151 |
my @debits = $account->outstanding_debits; |
| 152 |
is( scalar @debits, 0, 'no debits' ); |
| 153 |
|
| 154 |
$schema->storage->txn_rollback; |
| 155 |
}; |
| 156 |
}; |