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

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

Return to bug 17553