Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 3; |
6 |
use Test::MockModule; |
7 |
|
8 |
use C4::Biblio; |
9 |
use C4::Items; |
10 |
use C4::Members; |
11 |
use C4::Branch; |
12 |
use C4::Category; |
13 |
use C4::Circulation; |
14 |
use MARC::Record; |
15 |
|
16 |
my $dbh = C4::Context->dbh; |
17 |
$dbh->{AutoCommit} = 0; |
18 |
$dbh->{RaiseError} = 1; |
19 |
|
20 |
$dbh->do(q|DELETE FROM issues|); |
21 |
$dbh->do(q|DELETE FROM borrowers|); |
22 |
$dbh->do(q|DELETE FROM items|); |
23 |
$dbh->do(q|DELETE FROM branches|); |
24 |
$dbh->do(q|DELETE FROM biblio|); |
25 |
$dbh->do(q|DELETE FROM categories|); |
26 |
|
27 |
my $branchcode = 'B'; |
28 |
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } ); |
29 |
|
30 |
my $categorycode = 'C'; |
31 |
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)", |
32 |
undef, $categorycode ); |
33 |
|
34 |
my %item_branch_infos = ( |
35 |
homebranch => $branchcode, |
36 |
holdingbranch => $branchcode, |
37 |
); |
38 |
|
39 |
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' ); |
40 |
my $itemnumber1 = |
41 |
AddItem( { barcode => '0101', %item_branch_infos }, $biblionumber1 ); |
42 |
my $itemnumber2 = |
43 |
AddItem( { barcode => '0102', %item_branch_infos }, $biblionumber1 ); |
44 |
|
45 |
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' ); |
46 |
my $itemnumber3 = |
47 |
AddItem( { barcode => '0103', %item_branch_infos }, $biblionumber2 ); |
48 |
|
49 |
my $borrowernumber = |
50 |
AddMember( categorycode => $categorycode, branchcode => $branchcode ); |
51 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
52 |
|
53 |
my $module = new Test::MockModule('C4::Context'); |
54 |
$module->mock( 'userenv', sub { { branch => $branchcode } } ); |
55 |
|
56 |
AddIssue( $borrower, '0101', DateTime->now->subtract( days => 1 ) ); |
57 |
AddIssue( $borrower, '0102', DateTime->now->subtract( days => 5 ) ); |
58 |
AddIssue( $borrower, '0103' ); |
59 |
|
60 |
my $overdues = C4::Members::GetOverdues( $borrowernumber ); |
61 |
is( @$overdues, 2, 'GetOverdues returns the correct number of elements' ); |
62 |
is( $overdues->[0]->{itemnumber}, $itemnumber1, 'First overdue is correct' ); |
63 |
is( $overdues->[1]->{itemnumber}, $itemnumber2, 'Second overdue is correct' ); |
64 |
|