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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +55 lines)
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
(-)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