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

(-)a/t/db_dependent/Accounts.t (-2 / +11 lines)
Lines 27-32 use t::lib::TestBuilder; Link Here
27
use Koha::Account;
27
use Koha::Account;
28
use Koha::Account::Lines;
28
use Koha::Account::Lines;
29
use Koha::Account::Line;
29
use Koha::Account::Line;
30
use Koha::Account::Offsets;
30
31
31
BEGIN {
32
BEGIN {
32
    use_ok('C4::Accounts');
33
    use_ok('C4::Accounts');
Lines 253-259 subtest "Koha::Account::pay tests" => sub { Link Here
253
254
254
subtest "More Koha::Account::pay tests" => sub {
255
subtest "More Koha::Account::pay tests" => sub {
255
256
256
    plan tests => 6;
257
    plan tests => 8;
257
258
258
    # Create a borrower
259
    # Create a borrower
259
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
260
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 283-288 subtest "More Koha::Account::pay tests" => sub { Link Here
283
    # make the full payment
284
    # make the full payment
284
    $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
285
    $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
285
286
287
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
288
    is( $offset->amount(), '-100.000000', 'Offset amount is -100.00' );
289
    is( $offset->type(), 'Payment', 'Offset type is Payment' );
290
286
    my $stat = $schema->resultset('Statistic')->search({
291
    my $stat = $schema->resultset('Statistic')->search({
287
        branch  => $branch,
292
        branch  => $branch,
288
        type    => 'payment'
293
        type    => 'payment'
Lines 302-308 subtest "More Koha::Account::pay tests" => sub { Link Here
302
307
303
subtest "Even more Koha::Account::pay tests" => sub {
308
subtest "Even more Koha::Account::pay tests" => sub {
304
309
305
    plan tests => 6;
310
    plan tests => 8;
306
311
307
    # Create a borrower
312
    # Create a borrower
308
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
313
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 333-338 subtest "Even more Koha::Account::pay tests" => sub { Link Here
333
    # make the full payment
338
    # make the full payment
334
    $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
339
    $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
335
340
341
    my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
342
    is( $offset->amount, '-60.000000', 'Offset amount is -60.00' );
343
    is( $offset->type, 'Payment', 'Offset type is payment' );
344
336
    my $stat = $schema->resultset('Statistic')->search({
345
    my $stat = $schema->resultset('Statistic')->search({
337
        branch  => $branch,
346
        branch  => $branch,
338
        type    => 'payment'
347
        type    => 'payment'
(-)a/t/db_dependent/Circulation.t (-1 / +14 lines)
Lines 27-36 use C4::Reserves; Link Here
27
use C4::Overdues qw(UpdateFine);
27
use C4::Overdues qw(UpdateFine);
28
use Koha::DateUtils;
28
use Koha::DateUtils;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::Account::Lines;
31
use Koha::Account::Offsets;
30
32
31
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
32
34
33
use Test::More tests => 86;
35
use Test::More tests => 93;
34
36
35
BEGIN {
37
BEGIN {
36
    use_ok('C4::Circulation');
38
    use_ok('C4::Circulation');
Lines 556-561 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
556
        }
558
        }
557
    );
559
    );
558
560
561
    my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next();
562
    is( $line->accounttype, 'FU', 'Account line type is FU' );
563
    is( $line->lastincrement, '15.000000', 'Account line last increment is 15.00' );
564
    is( $line->amountoutstanding, '15.000000', 'Account line amount outstanding is 15.00' );
565
    is( $line->amount, '15.000000', 'Account line amount is 15.00' );
566
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
567
568
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
569
    is( $offset->type, 'Fine', 'Account offset type is Fine' );
570
    is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
571
559
    LostItem( $itemnumber, 1 );
572
    LostItem( $itemnumber, 1 );
560
573
561
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
574
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-1 / +11 lines)
Lines 17-28 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 6;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
24
use C4::Accounts qw( manualinvoice );
24
use C4::Accounts qw( manualinvoice );
25
use C4::Circulation qw( CanBookBeIssued );
25
use C4::Circulation qw( CanBookBeIssued );
26
use Koha::Account::Lines;
27
use Koha::Account::Offsets;
26
28
27
my $schema = Koha::Database->new->schema;
29
my $schema = Koha::Database->new->schema;
28
$schema->storage->txn_begin;
30
$schema->storage->txn_begin;
Lines 62-67 manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 ); Link Here
62
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
64
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
63
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
65
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
64
66
67
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
68
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
69
is( $accountline->accounttype, "L", "Account type is L" );
70
71
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
72
is( $offset->type, 'Manual Debit', 'Got correct offset type' );
73
is( $offset->amount, '10.000000', 'Got amount of $10.00' );
74
65
$schema->storage->txn_rollback;
75
$schema->storage->txn_rollback;
66
76
67
1;
77
1;
(-)a/t/db_dependent/Koha/Checkouts.t~HEAD (+63 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 4;
23
24
use Koha::Checkout;
25
use Koha::Checkouts;
26
use Koha::Database;
27
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
33
my $builder         = t::lib::TestBuilder->new;
34
my $library         = $builder->build( { source => 'Branch' } );
35
my $patron          = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } );
36
my $item_1          = $builder->build( { source => 'Item' } );
37
my $item_2          = $builder->build( { source => 'Item' } );
38
my $nb_of_checkouts = Koha::Checkouts->search->count;
39
my $new_checkout_1  = Koha::Checkout->new(
40
    {   borrowernumber => $patron->{borrowernumber},
41
        itemnumber     => $item_1->{itemnumber},
42
        branchcode     => $library->{branchcode},
43
    }
44
)->store;
45
my $new_checkout_2 = Koha::Checkout->new(
46
    {   borrowernumber => $patron->{borrowernumber},
47
        itemnumber     => $item_2->{itemnumber},
48
        branchcode     => $library->{branchcode},
49
    }
50
)->store;
51
52
like( $new_checkout_1->issue_id, qr|^\d+$|, 'Adding a new checkout should have set the issue_id' );
53
is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts should have been added' );
54
55
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id );
56
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' );
57
58
$retrieved_checkout_1->delete;
59
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' );
60
61
$schema->storage->txn_rollback;
62
63
1;
(-)a/t/db_dependent/Patron/Relationships.t (-1 / +181 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 67;
21
22
use C4::Context;
23
24
use t::lib::TestBuilder;
25
26
BEGIN {
27
    use_ok('Koha::Objects');
28
    use_ok('Koha::Patrons');
29
    use_ok('Koha::Patron::Relationship');
30
    use_ok('Koha::Patron::Relationships');
31
}
32
33
# Start transaction
34
my $dbh = C4::Context->dbh;
35
$dbh->{AutoCommit} = 0;
36
$dbh->{RaiseError} = 1;
37
38
my $builder = t::lib::TestBuilder->new();
39
40
# Father
41
my $kyle = Koha::Patrons->find(
42
    $builder->build(
43
        {
44
            source => 'Borrower',
45
            value  => {
46
                firstname => 'Kyle',
47
                surname   => 'Hall',
48
            }
49
        }
50
    )->{borrowernumber}
51
);
52
53
# Mother
54
my $chelsea = Koha::Patrons->find(
55
    $builder->build(
56
        {
57
            source => 'Borrower',
58
            value  => {
59
                firstname => 'Chelsea',
60
                surname   => 'Hall',
61
            }
62
        }
63
    )->{borrowernumber}
64
);
65
66
# Children
67
my $daria = Koha::Patrons->find(
68
    $builder->build(
69
        {
70
            source => 'Borrower',
71
            value  => {
72
                firstname => 'Daria',
73
                surname   => 'Hall',
74
            }
75
        }
76
    )->{borrowernumber}
77
);
78
79
my $kylie = Koha::Patrons->find(
80
    $builder->build(
81
        {
82
            source => 'Borrower',
83
            value  => {
84
                firstname => 'Kylie',
85
                surname   => 'Hall',
86
            }
87
        }
88
    )->{borrowernumber}
89
);
90
91
Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $daria->id, relationship => 'father' })->store();
92
Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $kylie->id, relationship => 'father' })->store();
93
Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $daria->id, relationship => 'mother' })->store();
94
Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => $kylie->id, relationship => 'mother' })->store();
95
Koha::Patron::Relationship->new({ firstname => 'John', surname => 'Hall', guarantee_id => $daria->id, relationship => 'grandfather' })->store();
96
Koha::Patron::Relationship->new({ firstname => 'Debra', surname => 'Hall', guarantee_id => $daria->id, relationship => 'grandmother' })->store();
97
Koha::Patron::Relationship->new({ firstname => 'John', surname => 'Hall', guarantee_id => $kylie->id, relationship => 'grandfather' })->store();
98
Koha::Patron::Relationship->new({ firstname => 'Debra', surname => 'Hall', guarantee_id => $kylie->id, relationship => 'grandmother' })->store();
99
100
my @gr;
101
102
@gr = $kyle->guarantee_relationships();
103
is( @gr, 2, 'Found 2 guarantee relationships for father' );
104
is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
105
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
106
is( $gr[0]->relationship, 'father', 'Relationship is father' );
107
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
108
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
109
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
110
is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
111
112
is( $gr[1]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
113
is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
114
is( $gr[1]->relationship, 'father', 'Relationship is father' );
115
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
116
is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
117
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
118
is( $gr[1]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
119
120
@gr = $chelsea->guarantee_relationships();
121
is( @gr, 2, 'Found 2 guarantee relationships for mother' );
122
is( $gr[0]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
123
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
124
is( $gr[0]->relationship, 'mother', 'Relationship is mother' );
125
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
126
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
127
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
128
is( $gr[0]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
129
130
is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
131
is( $gr[1]->guarantee_id, $kylie->id, 'Guarantee matches for first relationship' );
132
is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
133
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
134
is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct guarantee' );
135
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
136
is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
137
138
@gr = $daria->guarantor_relationships();
139
is( @gr, 4, 'Found 4 guarantor relationships for child' );
140
is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' );
141
is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
142
is( $gr[0]->relationship, 'father', 'Relationship is father' );
143
is( ref($gr[0]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
144
is( $gr[0]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
145
is( ref($gr[0]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
146
is( $gr[0]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' );
147
148
is( $gr[1]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' );
149
is( $gr[1]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' );
150
is( $gr[1]->relationship, 'mother', 'Relationship is mother' );
151
is( ref($gr[1]->guarantee), 'Koha::Patron', 'Method guarantee returns a Koha::Patron' );
152
is( $gr[1]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct guarantee' );
153
is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' );
154
is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' );
155
156
is( $gr[2]->guarantor_id, undef, 'Grandfather has no id, not a Koha patron' );
157
is( $gr[2]->firstname, 'John', 'Grandfather has first name of John' );
158
is( $gr[2]->surname, 'Hall', 'Grandfather has surname of Hall' );
159
is( $gr[2]->guarantor, undef, 'Calling guarantor method for Grandfather returns undef' );
160
161
is( $gr[3]->guarantor_id, undef, 'Grandmother has no id, not a Koha patron' );
162
is( $gr[3]->firstname, 'Debra', 'Grandmother has first name of John' );
163
is( $gr[3]->surname, 'Hall', 'Grandmother has surname of Hall' );
164
is( $gr[3]->guarantor, undef, 'Calling guarantor method for Grandmother returns undef' );
165
166
my @siblings = $daria->siblings;
167
is( @siblings, 1, 'Method siblings called in list context returns list' );
168
is( ref($siblings[0]), 'Koha::Patron', 'List contains a Koha::Patron' );
169
is( $siblings[0]->firstname, 'Kylie', 'Sibling from list first name matches correctly' );
170
is( $siblings[0]->surname, 'Hall', 'Sibling from list surname matches correctly' );
171
is( $siblings[0]->id, $kylie->id, 'Sibling from list patron id matches correctly' );
172
173
my $siblings = $daria->siblings;
174
my $sibling = $siblings->next();
175
is( ref($siblings), 'Koha::Patrons', 'Calling siblings in scalar context results in a Koha::Patrons object' );
176
is( ref($sibling), 'Koha::Patron', 'Method next returns a Koha::Patron' );
177
is( $sibling->firstname, 'Kylie', 'Sibling from scalar first name matches correctly' );
178
is( $sibling->surname, 'Hall', 'Sibling from scalar surname matches correctly' );
179
is( $sibling->id, $kylie->id, 'Sibling from scalar patron id matches correctly' );
180
181
1;

Return to bug 14826