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

(-)a/t/db_dependent/Koha/Patrons.t (+69 lines)
Lines 27-32 use JSON; Link Here
27
27
28
use C4::Biblio;
28
use C4::Biblio;
29
use C4::Circulation;
29
use C4::Circulation;
30
30
use C4::Members;
31
use C4::Members;
31
use C4::Circulation;
32
use C4::Circulation;
32
33
Lines 1119-1124 subtest 'is_child | is_adult' => sub { Link Here
1119
    $patron_other->delete;
1120
    $patron_other->delete;
1120
};
1121
};
1121
1122
1123
subtest 'get_overdues' => sub {
1124
    plan tests => 7;
1125
1126
    my $library = $builder->build( { source => 'Branch' } );
1127
    my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' );
1128
    my $item_1 = $builder->build(
1129
        {
1130
            source => 'Item',
1131
            value  => {
1132
                homebranch    => $library->{branchcode},
1133
                holdingbranch => $library->{branchcode},
1134
                biblionumber  => $biblionumber_1
1135
            }
1136
        }
1137
    );
1138
    my $item_2 = $builder->build(
1139
        {
1140
            source => 'Item',
1141
            value  => {
1142
                homebranch    => $library->{branchcode},
1143
                holdingbranch => $library->{branchcode},
1144
                biblionumber  => $biblionumber_1
1145
            }
1146
        }
1147
    );
1148
    my ($biblionumber_2) = AddBiblio( MARC::Record->new, '' );
1149
    my $item_3 = $builder->build(
1150
        {
1151
            source => 'Item',
1152
            value  => {
1153
                homebranch    => $library->{branchcode},
1154
                holdingbranch => $library->{branchcode},
1155
                biblionumber  => $biblionumber_2
1156
            }
1157
        }
1158
    );
1159
    my $patron = $builder->build(
1160
        {
1161
            source => 'Borrower',
1162
            value  => { branchcode => $library->{branchcode} }
1163
        }
1164
    );
1165
1166
    my $module = new Test::MockModule('C4::Context');
1167
    $module->mock( 'userenv', sub { { branch => $library->{branchcode} } } );
1168
1169
    AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) );
1170
    AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) );
1171
    AddIssue( $patron, $item_3->{barcode} );
1172
1173
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
1174
    my $overdues = $patron->get_overdues;
1175
    is( $overdues->count, 2, 'Patron should have 2 overdues');
1176
    is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' );
1177
    is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' );
1178
1179
    my $o = $overdues->reset->next;
1180
    my $unblessed_overdue = $o->unblessed_all_relateds;
1181
    is( exists( $unblessed_overdue->{issuedate} ), 1, 'Fields from the issues table should be filled' );
1182
    is( exists( $unblessed_overdue->{itemcallnumber} ), 1, 'Fields from the items table should be filled' );
1183
    is( exists( $unblessed_overdue->{title} ), 1, 'Fields from the biblio table should be filled' );
1184
    is( exists( $unblessed_overdue->{itemtype} ), 1, 'Fields from the biblioitems table should be filled' );
1185
1186
    # Clean stuffs
1187
    $patron->checkouts->delete;
1188
    $patron->delete;
1189
};
1190
1122
$retrieved_patron_1->delete;
1191
$retrieved_patron_1->delete;
1123
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1192
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1124
1193
(-)a/t/db_dependent/Members/GetOverdues.t (-81 lines)
Lines 1-80 Link Here
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 => 3;
21
use Test::MockModule;
22
23
use t::lib::TestBuilder;
24
25
use C4::Biblio;
26
use C4::Items;
27
use C4::Members;
28
use C4::Circulation;
29
use Koha::Libraries;
30
use Koha::Patrons;
31
use MARC::Record;
32
33
my $schema = Koha::Database->schema;
34
my $dbh = C4::Context->dbh;
35
$schema->storage->txn_begin;
36
37
my $builder = t::lib::TestBuilder->new;
38
39
$dbh->do(q|DELETE FROM issues|);
40
$dbh->do(q|DELETE FROM borrowers|);
41
$dbh->do(q|DELETE FROM items|);
42
$dbh->do(q|DELETE FROM branches|);
43
$dbh->do(q|DELETE FROM biblio|);
44
$dbh->do(q|DELETE FROM categories|);
45
46
my $branchcode   = $builder->build( { source => 'Branch' } )->{branchcode};
47
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
48
my $itemtype     = $builder->build( { source => 'Itemtype' } )->{itemtype};
49
50
my %item_infos = (
51
    homebranch    => $branchcode,
52
    holdingbranch => $branchcode,
53
    itype         => $itemtype
54
);
55
56
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' );
57
my $itemnumber1 =
58
  AddItem( { barcode => '0101', %item_infos }, $biblionumber1 );
59
my $itemnumber2 =
60
  AddItem( { barcode => '0102', %item_infos }, $biblionumber1 );
61
62
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' );
63
my $itemnumber3 =
64
  AddItem( { barcode => '0103', %item_infos }, $biblionumber2 );
65
66
my $borrowernumber =
67
  AddMember( categorycode => $categorycode, branchcode => $branchcode );
68
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
69
70
my $module = new Test::MockModule('C4::Context');
71
$module->mock( 'userenv', sub { { branch => $branchcode } } );
72
73
AddIssue( $borrower, '0101', DateTime->now->subtract( days =>  1 ) );
74
AddIssue( $borrower, '0102', DateTime->now->subtract( days =>  5 ) );
75
AddIssue( $borrower, '0103' );
76
77
my $overdues = C4::Members::GetOverduesForPatron( $borrowernumber );
78
is( @$overdues, 2, 'GetOverduesForPatron returns the correct number of elements' );
79
is( $overdues->[0]->{itemnumber}, $itemnumber1, 'First overdue is correct' );
80
is( $overdues->[1]->{itemnumber}, $itemnumber2, 'Second overdue is correct' );
81
- 

Return to bug 17553