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
=> 21;
22 use t
::lib
::TestBuilder
;
31 my $schema = Koha
::Database
->schema;
32 $schema->storage->txn_begin;
33 my $dbh = C4
::Context
->dbh;
35 my $builder = t
::lib
::TestBuilder
->new;
37 $dbh->do(q
|DELETE FROM issues
|);
38 $dbh->do(q
|DELETE FROM items
|);
39 $dbh->do(q
|DELETE FROM borrowers
|);
40 $dbh->do(q
|DELETE FROM branches
|);
41 $dbh->do(q
|DELETE FROM biblio
|);
42 $dbh->do(q
|DELETE FROM items
|);
43 $dbh->do(q
|DELETE FROM categories
|);
48 my $branchcode = $builder->build( { source
=> 'Branch' } )->{branchcode
};
51 my $categorycode = $builder->build( { source
=> 'Category' } )->{categorycode
};
54 my $itemtype = $builder->build( { source
=> 'Itemtype' } )->{itemtype
};
57 homebranch
=> $branchcode,
58 holdingbranch
=> $branchcode,
62 my ($biblionumber1) = AddBiblio
(MARC
::Record
->new, '');
63 my $barcode1 = '0101';
64 Koha
::Item
->new({ barcode
=> $barcode1, %item_info, biblionumber
=> $biblionumber1 })->store;
65 my ($biblionumber2) = AddBiblio
(MARC
::Record
->new, '');
66 my $barcode2 = '0202';
67 Koha
::Item
->new({ barcode
=> $barcode2, %item_info, biblionumber
=> $biblionumber2 })->store;
69 my $borrowernumber1 = Koha
::Patron
->new({categorycode
=> $categorycode, branchcode
=> $branchcode})->store->borrowernumber;
70 my $borrowernumber2 = Koha
::Patron
->new({categorycode
=> $categorycode, branchcode
=> $branchcode})->store->borrowernumber;
71 # FIXME following code must be simplified to use the Koha::Patron objects
72 my $borrower1 = Koha
::Patrons
->find( $borrowernumber1 )->unblessed;
73 my $borrower2 = Koha
::Patrons
->find( $borrowernumber2 )->unblessed;
75 my $module = new Test
::MockModule
('C4::Context');
76 $module->mock('userenv', sub { { branch
=> $branchcode } });
79 my $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
80 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
81 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
82 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
83 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
84 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
85 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
86 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns unef' );
87 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
88 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
89 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
90 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
91 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
92 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
94 AddIssue
($borrower1, '0101');
95 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
96 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
97 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
98 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
99 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
100 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
101 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
102 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
103 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
104 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
105 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
106 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
107 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
108 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
110 AddIssue
($borrower2, '0202');
111 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
();
112 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
113 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
(undef, $biblionumber1);
114 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
115 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, undef);
116 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
117 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber1);
118 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
119 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber1, $biblionumber2);
120 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
121 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber1);
122 is
( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
123 $check_if_issued = C4
::Circulation
::CheckIfIssuedToPatron
($borrowernumber2, $biblionumber2);
124 is
( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );