3 # This file is part of Koha.
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.
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.
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>.
20 use Test
::More tests
=> 3;
23 use t
::lib
::TestBuilder
;
32 my $schema = Koha
::Database
->schema;
33 my $dbh = C4
::Context
->dbh;
34 $schema->storage->txn_begin;
36 my $builder = t
::lib
::TestBuilder
->new;
38 $dbh->do(q
|DELETE FROM issues
|);
39 $dbh->do(q
|DELETE FROM borrowers
|);
40 $dbh->do(q
|DELETE FROM items
|);
41 $dbh->do(q
|DELETE FROM branches
|);
42 $dbh->do(q
|DELETE FROM biblio
|);
43 $dbh->do(q
|DELETE FROM categories
|);
45 my $branchcode = $builder->build( { source
=> 'Branch' } )->{branchcode
};
46 my $categorycode = $builder->build( { source
=> 'Category' } )->{categorycode
};
47 my $itemtype = $builder->build( { source
=> 'Itemtype' } )->{itemtype
};
50 homebranch
=> $branchcode,
51 holdingbranch
=> $branchcode,
55 my ($biblionumber1) = AddBiblio
( MARC
::Record
->new, '' );
57 AddItem
( { barcode
=> '0101', %item_infos }, $biblionumber1 );
59 AddItem
( { barcode
=> '0102', %item_infos }, $biblionumber1 );
61 my ($biblionumber2) = AddBiblio
( MARC
::Record
->new, '' );
63 AddItem
( { barcode
=> '0103', %item_infos }, $biblionumber2 );
66 AddMember
( categorycode
=> $categorycode, branchcode
=> $branchcode );
67 my $borrower = GetMember
( borrowernumber
=> $borrowernumber );
69 my $module = new Test
::MockModule
('C4::Context');
70 $module->mock( 'userenv', sub { { branch
=> $branchcode } } );
72 AddIssue
( $borrower, '0101', DateTime
->now->subtract( days
=> 1 ) );
73 AddIssue
( $borrower, '0102', DateTime
->now->subtract( days
=> 5 ) );
74 AddIssue
( $borrower, '0103' );
76 my $overdues = C4
::Members
::GetOverduesForPatron
( $borrowernumber );
77 is
( @
$overdues, 2, 'GetOverduesForPatron returns the correct number of elements' );
78 is
( $overdues->[0]->{itemnumber
}, $itemnumber1, 'First overdue is correct' );
79 is
( $overdues->[1]->{itemnumber
}, $itemnumber2, 'Second overdue is correct' );