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
=> 20;
23 use t
::lib
::TestBuilder
;
33 my $schema = Koha
::Database
->schema;
34 my $dbh = C4
::Context
->dbh;
35 $schema->storage->txn_begin;
37 my $builder = t
::lib
::TestBuilder
->new;
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
|);
46 my $branchcode = $builder->build( { source
=> 'Branch' } )->{branchcode
};
47 my $categorycode = $builder->build( { source
=> 'Category' } )->{categorycode
};
48 my $itemtype = $builder->build( { source
=> 'Itemtype' } )->{itemtype
};
51 homebranch
=> $branchcode,
52 holdingbranch
=> $branchcode,
57 my ($biblionumber1) = AddBiblio
( MARC
::Record
->new, '' );
59 AddItem
( { barcode
=> '0101', %item_infos }, $biblionumber1 );
61 AddItem
( { barcode
=> '0102', %item_infos }, $biblionumber1 );
63 my ($biblionumber2) = AddBiblio
( MARC
::Record
->new, '' );
65 AddItem
( { barcode
=> '0203', %item_infos }, $biblionumber2 );
68 AddMember
( categorycode
=> $categorycode, branchcode
=> $branchcode );
70 AddMember
( categorycode
=> $categorycode, branchcode
=> $branchcode );
71 my $borrower1 = Koha
::Patrons
->find( $borrowernumber1 )->unblessed;
72 my $borrower2 = Koha
::Patrons
->find( $borrowernumber2 )->unblessed;
74 my $module = new Test
::MockModule
('C4::Context');
75 $module->mock( 'userenv', sub { { branch
=> $branchcode } } );
78 C4
::Members
::GetPendingIssues
( $borrowernumber1, $borrowernumber2 );
79 is
( @
$issues, 0, 'GetPendingIssues returns the correct number of elements' );
81 AddIssue
( $borrower1, '0101' );
82 $issues = C4
::Members
::GetPendingIssues
($borrowernumber1);
83 is
( @
$issues, 1, 'GetPendingIssues returns the correct number of elements' );
84 is
( $issues->[0]->{itemnumber
},
85 $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
87 C4
::Members
::GetPendingIssues
( $borrowernumber1, $borrowernumber2 );
88 is_deeply
( $issues, $issues_bis, 'GetPendingIssues functions correctly' );
89 $issues = C4
::Members
::GetPendingIssues
($borrowernumber2);
90 is
( @
$issues, 0, 'GetPendingIssues returns the correct number of elements' );
92 AddIssue
( $borrower1, '0102' );
93 $issues = C4
::Members
::GetPendingIssues
($borrowernumber1);
94 is
( @
$issues, 2, 'GetPendingIssues returns the correct number of elements' );
95 is
( $issues->[0]->{itemnumber
},
96 $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
97 is
( $issues->[1]->{itemnumber
},
98 $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
100 C4
::Members
::GetPendingIssues
( $borrowernumber1, $borrowernumber2 );
101 is_deeply
( $issues, $issues_bis, 'GetPendingIssues functions correctly' );
102 $issues = C4
::Members
::GetPendingIssues
($borrowernumber2);
103 is
( @
$issues, 0, 'GetPendingIssues returns the correct number of elements' );
105 AddIssue
( $borrower2, '0203' );
106 $issues = C4
::Members
::GetPendingIssues
($borrowernumber2);
107 is
( @
$issues, 1, 'GetAllIssues returns the correct number of elements' );
108 is
( $issues->[0]->{itemnumber
},
109 $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' );
110 $issues = C4
::Members
::GetPendingIssues
($borrowernumber1);
111 is
( @
$issues, 2, 'GetPendingIssues returns the correct number of elements' );
112 is
( $issues->[0]->{itemnumber
},
113 $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
114 is
( $issues->[1]->{itemnumber
},
115 $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
116 $issues = C4
::Members
::GetPendingIssues
( $borrowernumber1, $borrowernumber2 );
117 is
( @
$issues, 3, 'GetPendingIssues returns the correct number of elements' );
118 is
( $issues->[0]->{itemnumber
},
119 $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' );
120 is
( $issues->[1]->{itemnumber
},
121 $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' );
122 is
( $issues->[2]->{itemnumber
},
123 $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' );
125 $issues = C4
::Members
::GetPendingIssues
();
127 'GetPendingIssues without borrower numbers returns an empty array' );
129 $schema->storage->txn_begin;