Lines 19-27
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 7; |
22 |
use Test::More tests => 8; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
|
|
25 |
use C4::Members; |
26 |
|
25 |
use Koha::Patron; |
27 |
use Koha::Patron; |
26 |
use Koha::Patrons; |
28 |
use Koha::Patrons; |
27 |
use Koha::Database; |
29 |
use Koha::Database; |
Lines 173-178
subtest 'renew_account' => sub {
Link Here
|
173 |
$retrieved_patron->delete; |
175 |
$retrieved_patron->delete; |
174 |
}; |
176 |
}; |
175 |
|
177 |
|
|
|
178 |
subtest 'add_enrolment_fee_if_needed' => sub { |
179 |
plan tests => 4; |
180 |
|
181 |
my $enrolmentfee_K = 5; |
182 |
my $enrolmentfee_J = 10; |
183 |
my $enrolmentfee_YA = 20; |
184 |
|
185 |
$builder->build( { source => 'Category', value => { categorycode => 'K', enrolmentfee => $enrolmentfee_K } } ); |
186 |
$builder->build( { source => 'Category', value => { categorycode => 'J', enrolmentfee => $enrolmentfee_J } } ); |
187 |
$builder->build( { source => 'Category', value => { categorycode => 'YA', enrolmentfee => $enrolmentfee_YA } } ); |
188 |
|
189 |
my %borrower_data = ( |
190 |
firstname => 'my firstname', |
191 |
surname => 'my surname', |
192 |
categorycode => 'K', |
193 |
branchcode => $library->{branchcode}, |
194 |
); |
195 |
|
196 |
my $borrowernumber = C4::Members::AddMember(%borrower_data); |
197 |
$borrower_data{borrowernumber} = $borrowernumber; |
198 |
|
199 |
my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber); |
200 |
is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" ); |
201 |
|
202 |
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 ); |
203 |
$borrower_data{categorycode} = 'J'; |
204 |
C4::Members::ModMember(%borrower_data); |
205 |
($total) = C4::Members::GetMemberAccountRecords($borrowernumber); |
206 |
is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " ); |
207 |
|
208 |
$borrower_data{categorycode} = 'K'; |
209 |
C4::Members::ModMember(%borrower_data); |
210 |
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 ); |
211 |
|
212 |
$borrower_data{categorycode} = 'J'; |
213 |
C4::Members::ModMember(%borrower_data); |
214 |
($total) = C4::Members::GetMemberAccountRecords($borrowernumber); |
215 |
is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) ); |
216 |
|
217 |
# Check with calling directly Koha::Patron->get_enrolment_fee_if_needed |
218 |
my $patron = Koha::Patrons->find($borrowernumber); |
219 |
$patron->categorycode('YA')->store; |
220 |
my $fee = $patron->add_enrolment_fee_if_needed; |
221 |
($total) = C4::Members::GetMemberAccountRecords($borrowernumber); |
222 |
is( $total, |
223 |
$enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA, |
224 |
"Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA ) |
225 |
); |
226 |
|
227 |
$patron->delete; |
228 |
}; |
229 |
|
176 |
$retrieved_patron_1->delete; |
230 |
$retrieved_patron_1->delete; |
177 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
231 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
178 |
|
232 |
|