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 => 10;
22
use Test::More tests => 11;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use C4::Members;
25
use C4::Members;
Lines 251-256 subtest "delete" => sub { Link Here
251
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
251
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
252
};
252
};
253
253
254
subtest 'add_enrolment_fee_if_needed' => sub {
255
    plan tests => 4;
256
257
    my $enrolmentfee_K  = 5;
258
    my $enrolmentfee_J  = 10;
259
    my $enrolmentfee_YA = 20;
260
261
    $builder->build( { source => 'Category', value => { categorycode => 'K',  enrolmentfee => $enrolmentfee_K } } );
262
    $builder->build( { source => 'Category', value => { categorycode => 'J',  enrolmentfee => $enrolmentfee_J } } );
263
    $builder->build( { source => 'Category', value => { categorycode => 'YA', enrolmentfee => $enrolmentfee_YA } } );
264
265
    my %borrower_data = (
266
        firstname    => 'my firstname',
267
        surname      => 'my surname',
268
        categorycode => 'K',
269
        branchcode   => $library->{branchcode},
270
    );
271
272
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
273
    $borrower_data{borrowernumber} = $borrowernumber;
274
275
    my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
276
    is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
277
278
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
279
    $borrower_data{categorycode} = 'J';
280
    C4::Members::ModMember(%borrower_data);
281
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
282
    is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
283
284
    $borrower_data{categorycode} = 'K';
285
    C4::Members::ModMember(%borrower_data);
286
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
287
288
    $borrower_data{categorycode} = 'J';
289
    C4::Members::ModMember(%borrower_data);
290
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
291
    is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
292
293
    # Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
294
    my $patron = Koha::Patrons->find($borrowernumber);
295
    $patron->categorycode('YA')->store;
296
    my $fee = $patron->add_enrolment_fee_if_needed;
297
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
298
    is( $total,
299
        $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA,
300
        "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
301
    );
302
303
    $patron->delete;
304
};
305
254
$retrieved_patron_1->delete;
306
$retrieved_patron_1->delete;
255
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
307
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
256
308
(-)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