11 use Test
::More tests
=> 13;
14 use_ok
('C4::Circulation');
17 can_ok
( 'C4::Circulation', qw(
20 GetBranchBorrowerCircRule
27 my $dbh = C4
::Context
->dbh;
28 $dbh->{RaiseError
} = 1;
29 $dbh->{AutoCommit
} = 0;
31 $dbh->do(q
|DELETE FROM issues
|);
32 $dbh->do(q
|DELETE FROM items
|);
33 $dbh->do(q
|DELETE FROM borrowers
|);
34 $dbh->do(q
|DELETE FROM branches
|);
35 $dbh->do(q
|DELETE FROM categories
|);
36 $dbh->do(q
|DELETE FROM accountlines
|);
37 $dbh->do(q
|DELETE FROM itemtypes
|);
38 $dbh->do(q
|DELETE FROM branch_item_rules
|);
39 $dbh->do(q
|DELETE FROM branch_borrower_circ_rules
|);
40 $dbh->do(q
|DELETE FROM default_branch_circ_rules
|);
41 $dbh->do(q
|DELETE FROM default_circ_rules
|);
42 $dbh->do(q
|DELETE FROM default_branch_item_rules
|);
44 #Add branch and category
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',
67 branchname
=> 'Sample Branch2',
68 branchaddress1
=> 'sample adr1_2',
69 branchaddress2
=> 'sample adr2_2',
70 branchaddress3
=> 'sample adr3_2',
71 branchzip
=> 'sample zip2',
72 branchcity
=> 'sample city2',
73 branchstate
=> 'sample state2',
74 branchcountry
=> 'sample country2',
75 branchphone
=> 'sample phone2',
76 branchfax
=> 'sample fax2',
77 branchemail
=> 'sample email2',
78 branchurl
=> 'sample url2',
79 branchip
=> 'sample ip2',
80 branchprinter
=> undef,
81 opac_info
=> 'sample opac2',
83 ModBranch
($samplebranch1);
84 ModBranch
($samplebranch2);
87 categorycode
=> 'CAT1',
88 description
=> 'Description1',
89 enrolmentperiod
=> 'Null',
90 enrolmentperioddate
=> 'Null',
91 dateofbirthrequired
=> 'Null',
94 enrolmentfee
=> 'Null',
95 overduenoticerequired
=> 'Null',
99 category_type
=> 'Null'
102 "INSERT INTO categories (categorycode,
106 dateofbirthrequired ,
110 overduenoticerequired,
116 VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
119 $samplecat->{categorycode
}, $samplecat->{description
},
120 $samplecat->{enrolmentperiod
}, $samplecat->{enrolmentperioddate
},
121 $samplecat->{dateofbirthrequired
}, $samplecat->{finetype
},
122 $samplecat->{bulk
}, $samplecat->{enrolmentfee
},
123 $samplecat->{overduenoticerequired
}, $samplecat->{issuelimit
},
124 $samplecat->{reservefee
}, $samplecat->{hidelostitems
},
125 $samplecat->{category_type
}
129 my $sampleitemtype1 = {
131 description
=> 'BookDescription',
132 rentalcharge
=> '10.0',
135 summary
=> 'BookSummary'
137 my $sampleitemtype2 = {
139 description
=> 'DvdDescription',
140 rentalcharge
=> '5.0',
143 summary
=> 'DvdSummary'
146 "INSERT INTO itemtypes (itemtype,
153 VALUES( ?,?,?,?,?,?)";
154 my $sth = $dbh->prepare($query);
156 $sampleitemtype1->{itemtype
}, $sampleitemtype1->{description
},
157 $sampleitemtype1->{rentalcharge
}, $sampleitemtype1->{notforloan
},
158 $sampleitemtype1->{imageurl
}, $sampleitemtype1->{summary
}
161 $sampleitemtype2->{itemtype
}, $sampleitemtype2->{description
},
162 $sampleitemtype2->{rentalcharge
}, $sampleitemtype2->{notforloan
},
163 $sampleitemtype2->{imageurl
}, $sampleitemtype2->{summary
}
167 my $record = MARC
::Record
->new();
168 $record->append_fields(
169 MARC
::Field
->new( '952', '0', '0', a
=> $samplebranch1->{branchcode
} ) );
170 my ( $biblionumber, $biblioitemnumber ) = C4
::Biblio
::AddBiblio
( $record, '' );
172 # item 2 has home branch and holding branch samplebranch1
173 my @sampleitem1 = C4
::Items
::AddItem
(
175 barcode
=> 'barcode_1',
176 itemcallnumber
=> 'callnumber1',
177 homebranch
=> $samplebranch1->{branchcode
},
178 holdingbranch
=> $samplebranch1->{branchcode
}
182 my $item_id1 = $sampleitem1[2];
184 # item 2 has holding branch samplebranch2
185 my @sampleitem2 = C4
::Items
::AddItem
(
187 barcode
=> 'barcode_2',
188 itemcallnumber
=> 'callnumber2',
189 homebranch
=> $samplebranch2->{branchcode
},
190 holdingbranch
=> $samplebranch1->{branchcode
}
194 my $item_id2 = $sampleitem2[2];
196 # item 3 has item type sampleitemtype2 with noreturn policy
197 my @sampleitem3 = C4
::Items
::AddItem
(
199 barcode
=> 'barcode_3',
200 itemcallnumber
=> 'callnumber3',
201 homebranch
=> $samplebranch2->{branchcode
},
202 holdingbranch
=> $samplebranch2->{branchcode
},
203 itype
=> $sampleitemtype2->{itemtype
}
207 my $item_id3 = $sampleitem3[2];
210 my $borrower_id1 = C4
::Members
::AddMember
(
211 firstname
=> 'firstname1',
212 surname
=> 'surname1 ',
213 categorycode
=> $samplecat->{categorycode
},
214 branchcode
=> $samplebranch1->{branchcode
},
216 my $borrower_1 = C4
::Members
::GetMember
(borrowernumber
=> $borrower_id1);
219 "INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
222 $samplebranch1->{branchcode
},
223 $samplecat->{categorycode
}, 5
227 "INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
228 $dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' );
231 "INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
232 $dbh->do( $query, {}, $samplebranch2->{branchcode
}, 3, 1, 'holdingbranch' );
235 "INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
236 $sth = $dbh->prepare($query);
238 $samplebranch1->{branchcode
},
239 $sampleitemtype1->{itemtype
},
243 $samplebranch2->{branchcode
},
244 $sampleitemtype1->{itemtype
},
248 $samplebranch2->{branchcode
},
249 $sampleitemtype2->{itemtype
},
253 #Test GetBranchBorrowerCircRule
255 GetBranchBorrowerCircRule
(),
256 { maxissueqty
=> 4 },
257 "Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
260 GetBranchBorrowerCircRule
( $samplebranch2->{branchcode
} ),
261 { maxissueqty
=> 3 },
262 "Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
265 GetBranchBorrowerCircRule
(
266 $samplebranch1->{branchcode
},
267 $samplecat->{categorycode
}
269 { maxissueqty
=> 5 },
270 "GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
273 GetBranchBorrowerCircRule
( -1, -1 ),
274 { maxissueqty
=> 4 },
275 "GetBranchBorrower with wrong parameters returns tthe maxissueqty of default_circ_rules"
278 #Test GetBranchItemRule
281 $samplebranch1->{branchcode
},
282 $sampleitemtype1->{itemtype
}
284 { returnbranch
=> 'homebranch', holdallowed
=> 5 },
285 "GetBranchitem returns holdallowed and return branch"
289 { returnbranch
=> 'homebranch', holdallowed
=> 3 },
290 "Without parameters GetBranchItemRule returns the values in default_circ_rules"
293 GetBranchItemRule
( $samplebranch2->{branchcode
} ),
294 { returnbranch
=> 'holdingbranch', holdallowed
=> 1 },
295 "With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
298 GetBranchItemRule
( -1, -1 ),
299 { returnbranch
=> 'homebranch', holdallowed
=> 3 },
300 "With only one parametern GetBranchItemRule returns default values"
303 # Test return policies
304 C4
::Context
->set_preference('AutomaticItemReturn','0');
306 # item1 returned at branch2 should trigger transfer to homebranch
308 "INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
309 $dbh->do( $query, {}, $borrower_id1, $item_id1, $samplebranch1->{branchcode
} );
311 my ($doreturn, $messages, $iteminformation, $borrower) = AddReturn
('barcode_1',
312 $samplebranch2->{branchcode
});
313 is
( $messages->{NeedsTransfer
}, $samplebranch1->{branchcode
}, "AddReturn respects default return policy - return to homebranch" );
315 # item2 returned at branch2 should trigger transfer to holding branch
317 "INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
318 $dbh->do( $query, {}, $borrower_id1, $item_id2, $samplebranch2->{branchcode
} );
319 ($doreturn, $messages, $iteminformation, $borrower) = AddReturn
('barcode_2',
320 $samplebranch2->{branchcode
});
321 is
( $messages->{NeedsTransfer
}, $samplebranch1->{branchcode
}, "AddReturn respects branch return policy - item2->homebranch policy = 'holdingbranch'" );
323 # item3 should not trigger transfer - floating collection
325 "INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
326 $dbh->do( $query, {}, $borrower_id1, $item_id3, $samplebranch1->{branchcode
} );
327 ($doreturn, $messages, $iteminformation, $borrower) = AddReturn
('barcode_3',
328 $samplebranch1->{branchcode
});
329 is
($messages->{NeedsTransfer
},undef,"AddReturn respects branch item return policy - noreturn");