Line 0
Link Here
|
0 |
- |
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 C4::Biblio; |
21 |
use C4::Items; |
22 |
use Koha::Database; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
|
26 |
use Test::More tests => 7; |
27 |
|
28 |
BEGIN { |
29 |
use_ok('C4::Circulation'); |
30 |
} |
31 |
|
32 |
my $schema = Koha::Database->schema; |
33 |
$schema->storage->txn_begin; |
34 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $dbh = C4::Context->dbh; |
36 |
|
37 |
# Start transaction |
38 |
$dbh->{RaiseError} = 1; |
39 |
|
40 |
# Start with a clean slate |
41 |
$dbh->do('DELETE FROM issues'); |
42 |
|
43 |
my $library = $builder->build( |
44 |
{ |
45 |
source => 'Branch', |
46 |
} |
47 |
); |
48 |
|
49 |
my $borrower = $builder->build( |
50 |
{ |
51 |
source => 'Borrower', |
52 |
} |
53 |
); |
54 |
|
55 |
# Now, set a userenv |
56 |
C4::Context->_new_userenv('xxx'); |
57 |
C4::Context->set_userenv( |
58 |
0, 0, 0, 'firstname', 'surname', |
59 |
$library->{branchcode}, |
60 |
'Midway Public Library', |
61 |
'', '', '' |
62 |
); |
63 |
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'userenv set' ); |
64 |
|
65 |
my $biblio = MARC::Record->new(); |
66 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); |
67 |
|
68 |
my $barcode = '1234'; |
69 |
my ( undef, undef, $itemnumber ) = AddItem( |
70 |
{ |
71 |
homebranch => $library->{branchcode}, |
72 |
holdingbranch => $library->{branchcode}, |
73 |
barcode => $barcode, |
74 |
}, |
75 |
$biblionumber |
76 |
); |
77 |
|
78 |
$dbh->do('DELETE FROM issuingrules'); |
79 |
$schema->resultset('Issuingrule')->create( |
80 |
{ |
81 |
categorycode => '*', |
82 |
branchcode => '*', |
83 |
itemtype => '*', |
84 |
maxissueqty => 20, |
85 |
issuelength => 14, |
86 |
lengthunit => 'days', |
87 |
renewalsallowed => 99, |
88 |
renewalperiod => 7, |
89 |
} |
90 |
); |
91 |
|
92 |
my $issue = AddIssue( $borrower, $barcode ); |
93 |
|
94 |
my $item = Koha::Items->find($itemnumber); |
95 |
$item->itemlost(1)->store(); |
96 |
|
97 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
98 |
|
99 |
$dbh->do('DELETE FROM default_circ_rules'); |
100 |
$schema->resultset('DefaultCircRule')->create( |
101 |
{ |
102 |
renew_lost_allowed => 0, |
103 |
renew_lost_found => 0, |
104 |
} |
105 |
); |
106 |
|
107 |
my ( $ok, $error ); |
108 |
( $ok, $error ) = CanBookBeRenewed( $borrower->{borrowernumber}, $itemnumber ); |
109 |
|
110 |
is( $ok, 0, "Lost item cannot be renewed" ); |
111 |
is( $error, 'item_lost', "Lost item cannot be renewed, error is item_lost" ); |
112 |
|
113 |
$dbh->do('DELETE FROM default_circ_rules'); |
114 |
$schema->resultset('DefaultCircRule')->create( |
115 |
{ |
116 |
renew_lost_allowed => 1, |
117 |
renew_lost_found => 0, |
118 |
} |
119 |
); |
120 |
( $ok, $error ) = CanBookBeRenewed( $borrower->{borrowernumber}, $itemnumber ); |
121 |
|
122 |
is( $ok, 1, "Lost item can be renewed" ); |
123 |
|
124 |
AddRenewal( $borrower->{borrowernumber}, $itemnumber, $library->{branchcode} ); |
125 |
$item = Koha::Items->find($itemnumber); |
126 |
is( $item->itemlost, 1, |
127 |
"Item still lost after renewal with renew_lost_found = 0" ); |
128 |
|
129 |
$dbh->do('DELETE FROM default_circ_rules'); |
130 |
$schema->resultset('DefaultCircRule')->create( |
131 |
{ |
132 |
renew_lost_allowed => 1, |
133 |
renew_lost_found => 1, |
134 |
} |
135 |
); |
136 |
|
137 |
AddRenewal( $borrower->{borrowernumber}, $itemnumber, $library->{branchcode} ); |
138 |
$item = Koha::Items->find($itemnumber); |
139 |
is( $item->itemlost, 0, |
140 |
"Item no longer lost after renewal with renew_lost_found = 1" ); |
141 |
|
142 |
1; |