11 use Test
::More tests
=> 10;
14 use_ok
('C4::Circulation');
17 can_ok
( 'C4::Circulation', qw(
18 GetBranchBorrowerCircRule
24 my $dbh = C4
::Context
->dbh;
25 $dbh->{RaiseError
} = 1;
26 $dbh->{AutoCommit
} = 0;
28 $dbh->do(q
|DELETE FROM issues
|);
29 $dbh->do(q
|DELETE FROM items
|);
30 $dbh->do(q
|DELETE FROM borrowers
|);
31 $dbh->do(q
|DELETE FROM branches
|);
32 $dbh->do(q
|DELETE FROM categories
|);
33 $dbh->do(q
|DELETE FROM accountlines
|);
34 $dbh->do(q
|DELETE FROM itemtypes
|);
35 $dbh->do(q
|DELETE FROM branch_item_rules
|);
36 $dbh->do(q
|DELETE FROM branch_borrower_circ_rules
|);
37 $dbh->do(q
|DELETE FROM default_branch_circ_rules
|);
38 $dbh->do(q
|DELETE FROM default_circ_rules
|);
39 $dbh->do(q
|DELETE FROM default_branch_item_rules
|);
41 #Add branch and category
45 branchname
=> 'Sample Branch',
46 branchaddress1
=> 'sample adr1',
47 branchaddress2
=> 'sample adr2',
48 branchaddress3
=> 'sample adr3',
49 branchzip
=> 'sample zip',
50 branchcity
=> 'sample city',
51 branchstate
=> 'sample state',
52 branchcountry
=> 'sample country',
53 branchphone
=> 'sample phone',
54 branchfax
=> 'sample fax',
55 branchemail
=> 'sample email',
56 branchurl
=> 'sample url',
57 branchip
=> 'sample ip',
58 branchprinter
=> undef,
59 opac_info
=> 'sample opac',
64 branchname
=> 'Sample Branch2',
65 branchaddress1
=> 'sample adr1_2',
66 branchaddress2
=> 'sample adr2_2',
67 branchaddress3
=> 'sample adr3_2',
68 branchzip
=> 'sample zip2',
69 branchcity
=> 'sample city2',
70 branchstate
=> 'sample state2',
71 branchcountry
=> 'sample country2',
72 branchphone
=> 'sample phone2',
73 branchfax
=> 'sample fax2',
74 branchemail
=> 'sample email2',
75 branchurl
=> 'sample url2',
76 branchip
=> 'sample ip2',
77 branchprinter
=> undef,
78 opac_info
=> 'sample opac2',
80 ModBranch
($samplebranch1);
81 ModBranch
($samplebranch2);
84 categorycode
=> 'CAT1',
85 description
=> 'Description1',
86 enrolmentperiod
=> 'Null',
87 enrolmentperioddate
=> 'Null',
88 dateofbirthrequired
=> 'Null',
91 enrolmentfee
=> 'Null',
92 overduenoticerequired
=> 'Null',
96 category_type
=> 'Null'
99 "INSERT INTO categories (categorycode,
103 dateofbirthrequired ,
107 overduenoticerequired,
113 VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
116 $samplecat->{categorycode
}, $samplecat->{description
},
117 $samplecat->{enrolmentperiod
}, $samplecat->{enrolmentperioddate
},
118 $samplecat->{dateofbirthrequired
}, $samplecat->{finetype
},
119 $samplecat->{bulk
}, $samplecat->{enrolmentfee
},
120 $samplecat->{overduenoticerequired
}, $samplecat->{issuelimit
},
121 $samplecat->{reservefee
}, $samplecat->{hidelostitems
},
122 $samplecat->{category_type
}
126 my $sampleitemtype1 = {
128 description
=> 'BookDescription',
129 rentalcharge
=> '10.0',
132 summary
=> 'BookSummary'
134 my $sampleitemtype2 = {
136 description
=> 'DvdDescription',
137 rentalcharge
=> '5.0',
140 summary
=> 'DvdSummary'
143 "INSERT INTO itemtypes (itemtype,
150 VALUES( ?,?,?,?,?,?)";
151 my $sth = $dbh->prepare($query);
153 $sampleitemtype1->{itemtype
}, $sampleitemtype1->{description
},
154 $sampleitemtype1->{rentalcharge
}, $sampleitemtype1->{notforloan
},
155 $sampleitemtype1->{imageurl
}, $sampleitemtype1->{summary
}
158 $sampleitemtype2->{itemtype
}, $sampleitemtype2->{description
},
159 $sampleitemtype2->{rentalcharge
}, $sampleitemtype2->{notforloan
},
160 $sampleitemtype2->{imageurl
}, $sampleitemtype2->{summary
}
164 "INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
167 $samplebranch1->{branchcode
},
168 $samplecat->{categorycode
}, 5
171 "INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
172 $dbh->do( $query, {}, $samplebranch2->{branchcode
},
173 3, 1, $samplebranch2->{branchcode
} );
175 "INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
176 $dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode
} );
179 "INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
180 $sth = $dbh->prepare($query);
182 $samplebranch1->{branchcode
},
183 $sampleitemtype1->{itemtype
},
184 5, $samplebranch1->{branchcode
}
187 $samplebranch2->{branchcode
},
188 $sampleitemtype2->{itemtype
},
189 5, $samplebranch1->{branchcode
}
192 #Test GetBranchBorrowerCircRule
194 GetBranchBorrowerCircRule
(),
195 { maxissueqty
=> 4 },
196 "Without parameter, GetBranchBorrower returns the maxissueqty of default_circ_rules"
199 GetBranchBorrowerCircRule
( $samplebranch2->{branchcode
} ),
200 { maxissueqty
=> 3 },
201 "Without only the branchcode specified, GetBranchBorrower returns the maxissueqty corresponding"
204 GetBranchBorrowerCircRule
(
205 $samplebranch1->{branchcode
},
206 $samplecat->{categorycode
}
208 { maxissueqty
=> 5 },
209 "GetBranchBorrower returns the maxissueqty of the branch1 and the category1"
212 GetBranchBorrowerCircRule
( -1, -1 ),
213 { maxissueqty
=> 4 },
214 "GetBranchBorrower with wrong parameters returns tthe maxissueqty of default_circ_rules"
217 #Test GetBranchItemRule
220 $samplebranch1->{branchcode
},
221 $sampleitemtype1->{itemtype
}
223 { returnbranch
=> $samplebranch1->{branchcode
}, holdallowed
=> 5 },
224 "GetBranchitem returns holdallowed and return branch"
228 { returnbranch
=> $samplebranch1->{branchcode
}, holdallowed
=> 3 },
229 "Without parameters GetBranchItemRule returns the values in default_circ_rules"
232 GetBranchItemRule
( $samplebranch1->{branchcode
} ),
233 { returnbranch
=> $samplebranch1->{branchcode
}, holdallowed
=> 3 },
234 "With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
237 GetBranchItemRule
( -1, -1 ),
238 { returnbranch
=> $samplebranch1->{branchcode
}, holdallowed
=> 3 },
239 "With only one parametern GetBranchItemRule returns default values"