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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +53 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
23
24
use C4::Members;
24
use C4::Members;
25
25
Lines 147-152 subtest 'extend_subscription' => sub { Link Here
147
    $retrieved_patron->delete;
147
    $retrieved_patron->delete;
148
};
148
};
149
149
150
subtest 'add_enrolment_fee_if_needed' => sub {
151
    plan tests => 4;
152
153
    my $enrolmentfee_K  = 5;
154
    my $enrolmentfee_J  = 10;
155
    my $enrolmentfee_YA = 20;
156
157
    $builder->build( { source => 'Category', value => { categorycode => 'K',  enrolmentfee => $enrolmentfee_K } } );
158
    $builder->build( { source => 'Category', value => { categorycode => 'J',  enrolmentfee => $enrolmentfee_J } } );
159
    $builder->build( { source => 'Category', value => { categorycode => 'YA', enrolmentfee => $enrolmentfee_YA } } );
160
161
    my %borrower_data = (
162
        firstname    => 'my firstname',
163
        surname      => 'my surname',
164
        categorycode => 'K',
165
        branchcode   => $library->{branchcode},
166
    );
167
168
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
169
    $borrower_data{borrowernumber} = $borrowernumber;
170
171
    my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
172
    is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
173
174
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
175
    $borrower_data{categorycode} = 'J';
176
    C4::Members::ModMember(%borrower_data);
177
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
178
    is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
179
180
    $borrower_data{categorycode} = 'K';
181
    C4::Members::ModMember(%borrower_data);
182
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
183
184
    $borrower_data{categorycode} = 'J';
185
    C4::Members::ModMember(%borrower_data);
186
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
187
    is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
188
189
    # Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
190
    my $patron = Koha::Patrons->find($borrowernumber);
191
    $patron->categorycode('YA')->store;
192
    my $fee = $patron->add_enrolment_fee_if_needed;
193
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
194
    is( $total,
195
        $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA,
196
        "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
197
    );
198
199
    $patron->delete;
200
};
201
150
$retrieved_patron_1->delete;
202
$retrieved_patron_1->delete;
151
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
203
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
152
204
(-)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