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
=> 22;
22 use t
::lib
::TestBuilder
;
31 use_ok
('C4::Circulation');
34 my $schema = Koha
::Database
->schema;
35 $schema->storage->txn_begin;
37 my $builder = t
::lib
::TestBuilder
->new;
39 my $dbh = C4
::Context
->dbh;
40 $dbh->{AutoCommit
} = 0;
41 $dbh->{RaiseError
} = 1;
43 $dbh->do(q
|DELETE FROM issues
|);
44 $dbh->do(q
|DELETE FROM items
|);
45 $dbh->do(q
|DELETE FROM borrowers
|);
46 $dbh->do(q
|DELETE FROM branches
|);
47 $dbh->do(q
|DELETE FROM biblio
|);
48 $dbh->do(q
|DELETE FROM items
|);
49 $dbh->do(q
|DELETE FROM categories
|);
54 my $branchcode = $builder->build( { source
=> 'Branch' } )->{branchcode
};
57 my $categorycode = $builder->build( { source
=> 'Category' } )->{categorycode
};
60 my $itemtype = $builder->build( { source
=> 'Itemtype' } )->{itemtype
};
63 homebranch
=> $branchcode,
64 holdingbranch
=> $branchcode,
68 my ($biblionumber1) = AddBiblio
(MARC
::Record
->new, '');
69 my $barcode1 = '0101';
70 AddItem
({ barcode
=> $barcode1, %item_info }, $biblionumber1);
71 my ($biblionumber2) = AddBiblio
(MARC
::Record
->new, '');
72 my $barcode2 = '0202';
73 AddItem
({ barcode
=> $barcode2, %item_info }, $biblionumber2);
75 my $borrowernumber1 = AddMember
(categorycode
=> $categorycode, branchcode
=> $branchcode);
76 my $borrowernumber2 = AddMember
(categorycode
=> $categorycode, branchcode
=> $branchcode);
77 my $borrower1 = GetMember
(borrowernumber
=> $borrowernumber1);
78 my $borrower2 = GetMember
(borrowernumber
=> $borrowernumber2);
80 my $module = new Test
::MockModule
('C4::Context');
81 $module->mock('userenv', sub { { branch
=> $branchcode } });
84 my $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
85 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
86 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
87 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
88 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
89 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
90 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
91 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns unef' );
92 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
93 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
94 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
95 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
96 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
97 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
99 AddIssue
($borrower1, '0101');
100 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
101 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
102 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
103 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
104 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
105 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
106 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
107 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
108 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
109 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
110 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
111 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
112 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
113 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
115 AddIssue
($borrower2, '0202');
116 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
117 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
118 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
119 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
120 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
121 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
122 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
123 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
124 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
125 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
126 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
127 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
128 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
129 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );