View | Details | Raw Unified | Return to bug 16912
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patrons.t (-2 / +55 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 9;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Circulation;
25
use C4::Members;
26
26
use Koha::Patron;
27
use Koha::Patron;
27
use Koha::Patrons;
28
use Koha::Patrons;
28
use Koha::Database;
29
use Koha::Database;
Lines 207-212 subtest 'renew_account' => sub { Link Here
207
    $retrieved_patron->delete;
208
    $retrieved_patron->delete;
208
};
209
};
209
210
211
subtest 'add_enrolment_fee_if_needed' => sub {
212
    plan tests => 4;
213
214
    my $enrolmentfee_K  = 5;
215
    my $enrolmentfee_J  = 10;
216
    my $enrolmentfee_YA = 20;
217
218
    $builder->build( { source => 'Category', value => { categorycode => 'K',  enrolmentfee => $enrolmentfee_K } } );
219
    $builder->build( { source => 'Category', value => { categorycode => 'J',  enrolmentfee => $enrolmentfee_J } } );
220
    $builder->build( { source => 'Category', value => { categorycode => 'YA', enrolmentfee => $enrolmentfee_YA } } );
221
222
    my %borrower_data = (
223
        firstname    => 'my firstname',
224
        surname      => 'my surname',
225
        categorycode => 'K',
226
        branchcode   => $library->{branchcode},
227
    );
228
229
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
230
    $borrower_data{borrowernumber} = $borrowernumber;
231
232
    my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
233
    is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
234
235
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
236
    $borrower_data{categorycode} = 'J';
237
    C4::Members::ModMember(%borrower_data);
238
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
239
    is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
240
241
    $borrower_data{categorycode} = 'K';
242
    C4::Members::ModMember(%borrower_data);
243
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
244
245
    $borrower_data{categorycode} = 'J';
246
    C4::Members::ModMember(%borrower_data);
247
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
248
    is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
249
250
    # Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
251
    my $patron = Koha::Patrons->find($borrowernumber);
252
    $patron->categorycode('YA')->store;
253
    my $fee = $patron->add_enrolment_fee_if_needed;
254
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
255
    is( $total,
256
        $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA,
257
        "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
258
    );
259
260
    $patron->delete;
261
};
262
210
$retrieved_patron_1->delete;
263
$retrieved_patron_1->delete;
211
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
264
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
212
265
(-)a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t (-75 lines)
Lines 1-74 Link Here
1
use Modern::Perl;
2
use Test::More tests => 4;
3
4
use C4::Context;
5
use C4::Members;
6
use Koha::Database;
7
8
use t::lib::Mocks;
9
use t::lib::TestBuilder;
10
11
my $schema = Koha::Database->schema;
12
$schema->storage->txn_begin;
13
my $builder = t::lib::TestBuilder->new;
14
my $dbh = C4::Context->dbh;
15
$dbh->{RaiseError} = 1;
16
17
my $library = $builder->build({
18
    source => 'Branch',
19
});
20
21
my $enrolmentfee_K = 5;
22
my $enrolmentfee_J = 10;
23
my $enrolmentfee_YA = 20;
24
25
$dbh->do(q{
26
    UPDATE categories
27
    SET enrolmentfee=?
28
    WHERE categorycode=?
29
}, {}, $enrolmentfee_K, 'K' );
30
31
$dbh->do(q{
32
    UPDATE categories
33
    SET enrolmentfee=?
34
    WHERE categorycode=?
35
}, {}, $enrolmentfee_J, 'J' );
36
37
$dbh->do(q{
38
    UPDATE categories
39
    SET enrolmentfee=?
40
    WHERE categorycode=?
41
}, {}, $enrolmentfee_YA, 'YA' );
42
43
my %borrower_data = (
44
    firstname =>  'my firstname',
45
    surname => 'my surname',
46
    categorycode => 'K',
47
    branchcode => $library->{branchcode},
48
);
49
50
my $borrowernumber = C4::Members::AddMember( %borrower_data );
51
$borrower_data{borrowernumber} = $borrowernumber;
52
53
my ( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
54
is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
55
56
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
57
$borrower_data{categorycode} = 'J';
58
C4::Members::ModMember( %borrower_data );
59
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
60
is( $total, $enrolmentfee_K , "Kid growing and become a juvenile, but shouldn't pay for the upgrade ");
61
62
$borrower_data{categorycode} = 'K';
63
C4::Members::ModMember( %borrower_data );
64
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
65
66
$borrower_data{categorycode} = 'J';
67
C4::Members::ModMember( %borrower_data );
68
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
69
is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
70
71
# Check with calling directly AddEnrolmentFeeIfNeeded
72
C4::Members::AddEnrolmentFeeIfNeeded( 'YA', $borrowernumber );
73
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
74
is( $total, $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA, "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA ) );
75
- 

Return to bug 16912