Bug 12470: (followup) License statement missing
[srvgit] / t / db_dependent / Circulation / CheckIfIssuedToPatron.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 22;
21 use Test::MockModule;
22
23 use C4::Biblio;
24 use C4::Items;
25 use C4::Members;
26 use C4::Branch;
27 use C4::Category;
28 use MARC::Record;
29
30 BEGIN {
31     use_ok('C4::Circulation');
32 }
33
34
35 my $dbh = C4::Context->dbh;
36 $dbh->{AutoCommit} = 0;
37 $dbh->{RaiseError} = 1;
38
39 $dbh->do(q|DELETE FROM issues|);
40 $dbh->do(q|DELETE FROM items|);
41 $dbh->do(q|DELETE FROM borrowers|);
42 $dbh->do(q|DELETE FROM branches|);
43 $dbh->do(q|DELETE FROM biblio|);
44 $dbh->do(q|DELETE FROM items|);
45 $dbh->do(q|DELETE FROM categories|);
46
47
48 my $branchcode = 'B';
49 ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
50
51 my $categorycode = 'C';
52 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
53
54 my %item_branch_infos = (
55     homebranch => $branchcode,
56     holdingbranch => $branchcode,
57 );
58
59 my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
60 my $barcode1 = '0101';
61 AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1);
62 my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
63 my $barcode2 = '0202';
64 AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber2);
65
66 my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
67 my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode);
68 my $borrower1 = GetMember(borrowernumber => $borrowernumber1);
69 my $borrower2 = GetMember(borrowernumber => $borrowernumber2);
70
71 my $module = new Test::MockModule('C4::Context');
72 $module->mock('userenv', sub { { branch => $branchcode } });
73
74
75 my $check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
76 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
77 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
78 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
79 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef);
80 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
81 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1);
82 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns unef' );
83 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2);
84 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
85 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1);
86 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
87 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
88 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
89
90 AddIssue($borrower1, '0101');
91 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
92 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
93 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
94 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
95 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef);
96 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
97 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1);
98 is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
99 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2);
100 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
101 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1);
102 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
103 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
104 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
105
106 AddIssue($borrower2, '0202');
107 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron();
108 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' );
109 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1);
110 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' );
111 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef);
112 is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' );
113 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1);
114 is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
115 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2);
116 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
117 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1);
118 is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' );
119 $check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2);
120 is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' );
121
122 $dbh->rollback();
123
124 1;