8 use Koha::CirculationRules;
11 use Test::More tests => 8;
14 use_ok('C4::Circulation');
24 my $schema = Koha::Database->new->schema;
25 $schema->storage->txn_begin;
26 my $dbh = C4::Context->dbh;
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 edifact_ean|);
32 $dbh->do(q|DELETE FROM branches|);
33 $dbh->do(q|DELETE FROM categories|);
34 $dbh->do(q|DELETE FROM circulation_rules|);
38 #Add branch and category
41 branchname => 'Sample Branch',
42 branchaddress1 => 'sample adr1',
43 branchaddress2 => 'sample adr2',
44 branchaddress3 => 'sample adr3',
45 branchzip => 'sample zip',
46 branchcity => 'sample city',
47 branchstate => 'sample state',
48 branchcountry => 'sample country',
49 branchphone => 'sample phone',
50 branchfax => 'sample fax',
51 branchemail => 'sample email',
52 branchurl => 'sample url',
53 branchip => 'sample ip',
54 branchprinter => undef,
55 opac_info => 'sample opac',
59 branchname => 'Sample Branch2',
60 branchaddress1 => 'sample adr1_2',
61 branchaddress2 => 'sample adr2_2',
62 branchaddress3 => 'sample adr3_2',
63 branchzip => 'sample zip2',
64 branchcity => 'sample city2',
65 branchstate => 'sample state2',
66 branchcountry => 'sample country2',
67 branchphone => 'sample phone2',
68 branchfax => 'sample fax2',
69 branchemail => 'sample email2',
70 branchurl => 'sample url2',
71 branchip => 'sample ip2',
72 branchprinter => undef,
73 opac_info => 'sample opac2',
75 Koha::Library->new($samplebranch1)->store;
76 Koha::Library->new($samplebranch2)->store;
79 categorycode => 'CAT1',
80 description => 'Description1',
81 enrolmentperiod => undef,
82 enrolmentperioddate => undef,
83 dateofbirthrequired => undef,
86 enrolmentfee => undef,
87 overduenoticerequired => undef,
94 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
97 $samplecat->{categorycode}, $samplecat->{description},
98 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
99 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
100 $samplecat->{bulk}, $samplecat->{enrolmentfee},
101 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
102 $samplecat->{reservefee}, $samplecat->{hidelostitems},
103 $samplecat->{category_type}
114 #Test get_effective_rules
115 my $sampleissuingrule1 = {
116 branchcode => $samplebranch1->{branchcode},
117 categorycode => $samplecat->{categorycode},
124 lengthunit => 'days',
126 norenewalbefore => 6,
130 chargeperiod_charge_at => 0,
132 reservesallowed => 0,
133 hardduedate => '2013-01-01',
135 hardduedatecompare => 5,
136 overduefinescap => 0,
137 renewalsallowed => 0,
139 maxsuspensiondays => 0,
141 opacitemholds => 'N',
142 cap_fine_to_replacement_price => 0,
143 holds_per_record => 1,
144 article_requests => 'yes',
145 no_auto_renewal_after => undef,
146 no_auto_renewal_after_hard_limit => undef,
147 suspension_chargeperiod => 1,
148 holds_per_day => undef,
151 my $sampleissuingrule2 = {
152 branchcode => $samplebranch2->{branchcode},
153 categorycode => $samplecat->{categorycode},
156 renewalsallowed => 0,
158 norenewalbefore => 7,
160 reservesallowed => 0,
162 lengthunit => 'days',
164 hardduedatecompare => undef,
167 firstremind => undef,
168 chargeperiod => undef,
169 chargeperiod_charge_at => 0,
170 rentaldiscount => 2.00,
171 overduefinescap => undef,
172 accountsent => undef,
173 reservecharge => undef,
174 restrictedtype => undef,
175 maxsuspensiondays => 0,
177 opacitemholds => 'Y',
178 cap_fine_to_replacement_price => 0,
179 holds_per_record => 1,
180 article_requests => 'yes',
183 my $sampleissuingrule3 = {
184 branchcode => $samplebranch1->{branchcode},
185 categorycode => $samplecat->{categorycode},
188 renewalsallowed => 0,
190 norenewalbefore => 8,
192 reservesallowed => 0,
194 lengthunit => 'days',
196 hardduedatecompare => undef,
199 firstremind => undef,
200 chargeperiod => undef,
201 chargeperiod_charge_at => 0,
202 rentaldiscount => 3.00,
203 overduefinescap => undef,
204 accountsent => undef,
205 reservecharge => undef,
206 restrictedtype => undef,
207 maxsuspensiondays => 0,
209 opacitemholds => 'F',
210 cap_fine_to_replacement_price => 0,
211 holds_per_record => 1,
212 article_requests => 'yes',
216 Koha::CirculationRules->set_rules( $sampleissuingrule1 );
217 Koha::CirculationRules->set_rules( $sampleissuingrule2 );
218 Koha::CirculationRules->set_rules( $sampleissuingrule3 );
222 C4::Circulation::GetLoanLength(
223 $samplecat->{categorycode},
224 'BOOK', $samplebranch1->{branchcode}
226 { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
231 C4::Circulation::GetLoanLength(),
233 "Without parameters, GetLoanLength returns hardcoded values"
236 C4::Circulation::GetLoanLength( -1, -1 ),
238 "With wrong parameters, GetLoanLength returns hardcoded values"
241 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
243 "With only one parameter, GetLoanLength returns hardcoded values"
244 ); #NOTE : is that really what is expected?
246 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
248 "With only two parameters, GetLoanLength returns hardcoded values"
249 ); #NOTE : is that really what is expected?
251 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
255 lengthunit => 'days',
257 "With the correct number of parameters, GetLoanLength returns the expected values"
261 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
262 'BOOK', $samplebranch1->{branchcode} );
266 dt_from_string( $sampleissuingrule1->{rules}->{hardduedate}, 'iso' ),
267 $sampleissuingrule1->{rules}->{hardduedatecompare}
269 "GetHardDueDate returns the duedate and the duedatecompare"