Lines 1-15
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
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 |
|
3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
4 |
use t::lib::Mocks; |
19 |
|
5 |
use C4::Biblio; |
20 |
use C4::Biblio; |
6 |
use C4::Members; |
21 |
use C4::Members; |
7 |
use C4::Circulation; |
22 |
use C4::Circulation; |
8 |
use C4::Items; |
23 |
use C4::Items; |
9 |
use C4::Context; |
24 |
use C4::Context; |
10 |
use Koha::Library; |
|
|
11 |
|
25 |
|
12 |
use Test::More tests => 14; |
26 |
use Test::More tests => 14; |
|
|
27 |
use t::lib::Mocks; |
28 |
use t::lib::TestBuilder; |
13 |
|
29 |
|
14 |
BEGIN { |
30 |
BEGIN { |
15 |
use_ok('C4::Circulation'); |
31 |
use_ok('C4::Circulation'); |
Lines 24-33
can_ok( 'C4::Circulation', qw(
Link Here
|
24 |
) |
40 |
) |
25 |
); |
41 |
); |
26 |
|
42 |
|
27 |
#Start transaction |
43 |
my $schema = Koha::Database->schema; |
|
|
44 |
$schema->storage->txn_begin; |
28 |
my $dbh = C4::Context->dbh; |
45 |
my $dbh = C4::Context->dbh; |
29 |
$dbh->{RaiseError} = 1; |
|
|
30 |
$dbh->{AutoCommit} = 0; |
31 |
|
46 |
|
32 |
$dbh->do(q|DELETE FROM issues|); |
47 |
$dbh->do(q|DELETE FROM issues|); |
33 |
$dbh->do(q|DELETE FROM items|); |
48 |
$dbh->do(q|DELETE FROM items|); |
Lines 42-166
$dbh->do(q|DELETE FROM default_branch_circ_rules|);
Link Here
|
42 |
$dbh->do(q|DELETE FROM default_circ_rules|); |
57 |
$dbh->do(q|DELETE FROM default_circ_rules|); |
43 |
$dbh->do(q|DELETE FROM default_branch_item_rules|); |
58 |
$dbh->do(q|DELETE FROM default_branch_item_rules|); |
44 |
|
59 |
|
45 |
#Add branch and category |
60 |
my $builder = t::lib::TestBuilder->new(); |
46 |
my $samplebranch1 = { |
|
|
47 |
branchcode => 'SAB1', |
48 |
branchname => 'Sample Branch', |
49 |
branchaddress1 => 'sample adr1', |
50 |
branchaddress2 => 'sample adr2', |
51 |
branchaddress3 => 'sample adr3', |
52 |
branchzip => 'sample zip', |
53 |
branchcity => 'sample city', |
54 |
branchstate => 'sample state', |
55 |
branchcountry => 'sample country', |
56 |
branchphone => 'sample phone', |
57 |
branchfax => 'sample fax', |
58 |
branchemail => 'sample email', |
59 |
branchurl => 'sample url', |
60 |
branchip => 'sample ip', |
61 |
branchprinter => undef, |
62 |
opac_info => 'sample opac', |
63 |
}; |
64 |
my $samplebranch2 = { |
65 |
branchcode => 'SAB2', |
66 |
branchname => 'Sample Branch2', |
67 |
branchaddress1 => 'sample adr1_2', |
68 |
branchaddress2 => 'sample adr2_2', |
69 |
branchaddress3 => 'sample adr3_2', |
70 |
branchzip => 'sample zip2', |
71 |
branchcity => 'sample city2', |
72 |
branchstate => 'sample state2', |
73 |
branchcountry => 'sample country2', |
74 |
branchphone => 'sample phone2', |
75 |
branchfax => 'sample fax2', |
76 |
branchemail => 'sample email2', |
77 |
branchurl => 'sample url2', |
78 |
branchip => 'sample ip2', |
79 |
branchprinter => undef, |
80 |
opac_info => 'sample opac2', |
81 |
}; |
82 |
Koha::Library->new($samplebranch1)->store; |
83 |
Koha::Library->new($samplebranch2)->store; |
84 |
|
85 |
my $samplecat = { |
86 |
categorycode => 'CAT1', |
87 |
description => 'Description1', |
88 |
enrolmentperiod => 'Null', |
89 |
enrolmentperioddate => 'Null', |
90 |
dateofbirthrequired => 'Null', |
91 |
finetype => 'Null', |
92 |
bulk => 'Null', |
93 |
enrolmentfee => 'Null', |
94 |
overduenoticerequired => 'Null', |
95 |
issuelimit => 'Null', |
96 |
reservefee => 'Null', |
97 |
hidelostitems => 0, |
98 |
category_type => 'Null' |
99 |
}; |
100 |
my $query = |
101 |
"INSERT INTO categories (categorycode, |
102 |
description, |
103 |
enrolmentperiod, |
104 |
enrolmentperioddate, |
105 |
dateofbirthrequired , |
106 |
finetype, |
107 |
bulk, |
108 |
enrolmentfee, |
109 |
overduenoticerequired, |
110 |
issuelimit, |
111 |
reservefee, |
112 |
hidelostitems, |
113 |
category_type |
114 |
) |
115 |
VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)"; |
116 |
$dbh->do( |
117 |
$query, {}, |
118 |
$samplecat->{categorycode}, $samplecat->{description}, |
119 |
$samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate}, |
120 |
$samplecat->{dateofbirthrequired}, $samplecat->{finetype}, |
121 |
$samplecat->{bulk}, $samplecat->{enrolmentfee}, |
122 |
$samplecat->{overduenoticerequired}, $samplecat->{issuelimit}, |
123 |
$samplecat->{reservefee}, $samplecat->{hidelostitems}, |
124 |
$samplecat->{category_type} |
125 |
); |
126 |
|
61 |
|
127 |
#Add itemtypes |
62 |
# Add branch |
128 |
my $sampleitemtype1 = { |
63 |
my $samplebranch1 = $builder->build({ source => 'Branch' }); |
129 |
itemtype => 'BOOK', |
64 |
my $samplebranch2 = $builder->build({ source => 'Branch' }); |
130 |
description => 'BookDescription', |
65 |
# Add itemtypes |
131 |
rentalcharge => '10.0', |
66 |
my $no_circ_itemtype = $builder->build({ |
132 |
notforloan => 1, |
67 |
source => 'Itemtype', |
133 |
imageurl => 'Null', |
68 |
values => { |
134 |
summary => 'BookSummary' |
69 |
rentalcharge => '0', |
135 |
}; |
70 |
notforloan => 0 |
136 |
my $sampleitemtype2 = { |
71 |
} |
137 |
itemtype => 'DVD', |
72 |
}); |
138 |
description => 'DvdDescription', |
73 |
my $sampleitemtype1 = $builder->build({ |
139 |
rentalcharge => '5.0', |
74 |
source => 'Itemtype', |
140 |
notforloan => 0, |
75 |
values => { |
141 |
imageurl => 'Null', |
76 |
rentalcharge => '10.0', |
142 |
summary => 'DvdSummary' |
77 |
notforloan => 1 |
143 |
}; |
78 |
} |
144 |
$query = |
79 |
}); |
145 |
"INSERT INTO itemtypes (itemtype, |
80 |
my $sampleitemtype2 = $builder->build({ |
146 |
description, |
81 |
source => 'Itemtype', |
147 |
rentalcharge, |
82 |
values => { |
148 |
notforloan, |
83 |
rentalcharge => '5.0', |
149 |
imageurl, |
84 |
notforloan => 0 |
150 |
summary |
85 |
} |
151 |
) |
86 |
}); |
152 |
VALUES( ?,?,?,?,?,?)"; |
87 |
# Add Category |
153 |
my $sth = $dbh->prepare($query); |
88 |
my $samplecat = $builder->build({ |
154 |
$sth->execute( |
89 |
source => 'Category', |
155 |
$sampleitemtype1->{itemtype}, $sampleitemtype1->{description}, |
90 |
values => { |
156 |
$sampleitemtype1->{rentalcharge}, $sampleitemtype1->{notforloan}, |
91 |
hidelostitems => 0 |
157 |
$sampleitemtype1->{imageurl}, $sampleitemtype1->{summary} |
92 |
} |
158 |
); |
93 |
}); |
159 |
$sth->execute( |
|
|
160 |
$sampleitemtype2->{itemtype}, $sampleitemtype2->{description}, |
161 |
$sampleitemtype2->{rentalcharge}, $sampleitemtype2->{notforloan}, |
162 |
$sampleitemtype2->{imageurl}, $sampleitemtype2->{summary} |
163 |
); |
164 |
|
94 |
|
165 |
#Add biblio and item |
95 |
#Add biblio and item |
166 |
my $record = MARC::Record->new(); |
96 |
my $record = MARC::Record->new(); |
Lines 168-180
$record->append_fields(
Link Here
|
168 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
98 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
169 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); |
99 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); |
170 |
|
100 |
|
171 |
# item 2 has home branch and holding branch samplebranch1 |
101 |
# item 1 has home branch and holding branch samplebranch1 |
172 |
my @sampleitem1 = C4::Items::AddItem( |
102 |
my @sampleitem1 = C4::Items::AddItem( |
173 |
{ |
103 |
{ |
174 |
barcode => 'barcode_1', |
104 |
barcode => 'barcode_1', |
175 |
itemcallnumber => 'callnumber1', |
105 |
itemcallnumber => 'callnumber1', |
176 |
homebranch => $samplebranch1->{branchcode}, |
106 |
homebranch => $samplebranch1->{branchcode}, |
177 |
holdingbranch => $samplebranch1->{branchcode} |
107 |
holdingbranch => $samplebranch1->{branchcode}, |
|
|
108 |
itype => $no_circ_itemtype->{ itemtype } |
178 |
}, |
109 |
}, |
179 |
$biblionumber |
110 |
$biblionumber |
180 |
); |
111 |
); |
Lines 186-192
my @sampleitem2 = C4::Items::AddItem(
Link Here
|
186 |
barcode => 'barcode_2', |
117 |
barcode => 'barcode_2', |
187 |
itemcallnumber => 'callnumber2', |
118 |
itemcallnumber => 'callnumber2', |
188 |
homebranch => $samplebranch2->{branchcode}, |
119 |
homebranch => $samplebranch2->{branchcode}, |
189 |
holdingbranch => $samplebranch1->{branchcode} |
120 |
holdingbranch => $samplebranch1->{branchcode}, |
|
|
121 |
itype => $no_circ_itemtype->{ itemtype } |
190 |
}, |
122 |
}, |
191 |
$biblionumber |
123 |
$biblionumber |
192 |
); |
124 |
); |
Lines 220-226
is_deeply(
Link Here
|
220 |
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined" |
152 |
"Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined" |
221 |
); |
153 |
); |
222 |
|
154 |
|
223 |
$query = q| |
155 |
my $query = q| |
224 |
INSERT INTO branch_borrower_circ_rules |
156 |
INSERT INTO branch_borrower_circ_rules |
225 |
(branchcode, categorycode, maxissueqty, maxonsiteissueqty) |
157 |
(branchcode, categorycode, maxissueqty, maxonsiteissueqty) |
226 |
VALUES( ?, ?, ?, ? ) |
158 |
VALUES( ?, ?, ?, ? ) |
Lines 248-254
$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' );
Link Here
|
248 |
|
180 |
|
249 |
$query = |
181 |
$query = |
250 |
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
182 |
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
251 |
$sth = $dbh->prepare($query); |
183 |
my $sth = $dbh->prepare($query); |
252 |
$sth->execute( |
184 |
$sth->execute( |
253 |
$samplebranch1->{branchcode}, |
185 |
$samplebranch1->{branchcode}, |
254 |
$sampleitemtype1->{itemtype}, |
186 |
$sampleitemtype1->{itemtype}, |
Lines 343-347
$dbh->do( $query, {}, $borrower_id1, $item_id3, $samplebranch1->{branchcode} );
Link Here
|
343 |
$samplebranch1->{branchcode}); |
275 |
$samplebranch1->{branchcode}); |
344 |
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn"); |
276 |
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn"); |
345 |
|
277 |
|
|
|
278 |
$schema->storage->txn_rollback; |
346 |
|
279 |
|
347 |
$dbh->rollback; |
280 |
1; |
348 |
- |
|
|