8 use Koha::CirculationRules;
11 use t::lib::TestBuilder;
13 use Test::More tests => 9;
16 use_ok('C4::Circulation');
26 my $schema = Koha::Database->new->schema;
27 $schema->storage->txn_begin;
28 my $dbh = C4::Context->dbh;
30 $dbh->do(q|DELETE FROM issues|);
31 $dbh->do(q|DELETE FROM items|);
32 $dbh->do(q|DELETE FROM borrowers|);
33 $dbh->do(q|DELETE FROM edifact_ean|);
34 $dbh->do(q|DELETE FROM branches|);
35 $dbh->do(q|DELETE FROM categories|);
36 $dbh->do(q|DELETE FROM circulation_rules|);
40 #Add branch and category
43 branchname => 'Sample Branch',
44 branchaddress1 => 'sample adr1',
45 branchaddress2 => 'sample adr2',
46 branchaddress3 => 'sample adr3',
47 branchzip => 'sample zip',
48 branchcity => 'sample city',
49 branchstate => 'sample state',
50 branchcountry => 'sample country',
51 branchphone => 'sample phone',
52 branchfax => 'sample fax',
53 branchemail => 'sample email',
54 branchurl => 'sample url',
55 branchip => 'sample ip',
56 opac_info => 'sample opac',
60 branchname => 'Sample Branch2',
61 branchaddress1 => 'sample adr1_2',
62 branchaddress2 => 'sample adr2_2',
63 branchaddress3 => 'sample adr3_2',
64 branchzip => 'sample zip2',
65 branchcity => 'sample city2',
66 branchstate => 'sample state2',
67 branchcountry => 'sample country2',
68 branchphone => 'sample phone2',
69 branchfax => 'sample fax2',
70 branchemail => 'sample email2',
71 branchurl => 'sample url2',
72 branchip => 'sample ip2',
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}
106 my $builder = t::lib::TestBuilder->new;
107 my $sampleitemtype1 = $builder->build({ source => 'Itemtype' })->{itemtype};
108 my $sampleitemtype2 = $builder->build({ source => 'Itemtype' })->{itemtype};
118 #Test get_effective_rules
119 my $sampleissuingrule1 = {
120 branchcode => $samplebranch1->{branchcode},
121 categorycode => $samplecat->{categorycode},
122 itemtype => $sampleitemtype1,
125 lengthunit => 'days',
127 norenewalbefore => 6,
131 chargeperiod_charge_at => 0,
133 reservesallowed => 0,
134 hardduedate => '2013-01-01',
136 hardduedatecompare => 5,
137 overduefinescap => 0,
138 renewalsallowed => 0,
140 maxsuspensiondays => 0,
142 opacitemholds => 'N',
143 cap_fine_to_replacement_price => 0,
144 holds_per_record => 1,
145 article_requests => 'yes',
146 no_auto_renewal_after => undef,
147 no_auto_renewal_after_hard_limit => undef,
148 suspension_chargeperiod => 1,
149 holds_per_day => undef,
152 my $sampleissuingrule2 = {
153 branchcode => $samplebranch2->{branchcode},
154 categorycode => $samplecat->{categorycode},
155 itemtype => $sampleitemtype1,
157 renewalsallowed => 0,
159 norenewalbefore => 7,
161 reservesallowed => 0,
163 lengthunit => 'days',
165 hardduedatecompare => undef,
168 firstremind => undef,
169 chargeperiod => undef,
170 chargeperiod_charge_at => 0,
171 rentaldiscount => 2.00,
172 overduefinescap => undef,
173 maxsuspensiondays => 0,
175 opacitemholds => 'Y',
176 cap_fine_to_replacement_price => 0,
177 holds_per_record => 1,
178 article_requests => 'yes',
181 my $sampleissuingrule3 = {
182 branchcode => $samplebranch1->{branchcode},
183 categorycode => $samplecat->{categorycode},
184 itemtype => $sampleitemtype2,
186 renewalsallowed => 0,
188 norenewalbefore => 8,
190 reservesallowed => 0,
192 lengthunit => 'days',
194 hardduedatecompare => undef,
197 firstremind => undef,
198 chargeperiod => undef,
199 chargeperiod_charge_at => 0,
200 rentaldiscount => 3.00,
201 overduefinescap => undef,
202 maxsuspensiondays => 0,
204 opacitemholds => 'F',
205 cap_fine_to_replacement_price => 0,
206 holds_per_record => 1,
207 article_requests => 'yes',
211 Koha::CirculationRules->set_rules( $sampleissuingrule1 );
212 Koha::CirculationRules->set_rules( $sampleissuingrule2 );
213 Koha::CirculationRules->set_rules( $sampleissuingrule3 );
217 C4::Circulation::GetLoanLength(
218 $samplecat->{categorycode},
219 $sampleitemtype1, $samplebranch1->{branchcode}
221 { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
226 C4::Circulation::GetLoanLength(),
228 "Without parameters, GetLoanLength returns hardcoded values"
231 C4::Circulation::GetLoanLength( -1, -1 ),
233 "With wrong parameters, GetLoanLength returns hardcoded values"
236 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
238 "With only one parameter, GetLoanLength returns hardcoded values"
239 ); #NOTE : is that really what is expected?
241 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1 ),
243 "With only two parameters, GetLoanLength returns hardcoded values"
244 ); #NOTE : is that really what is expected?
246 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
250 lengthunit => 'days',
252 "With the correct number of parameters, GetLoanLength returns the expected values"
256 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
257 $sampleitemtype1, $samplebranch1->{branchcode} );
261 dt_from_string( $sampleissuingrule1->{rules}->{hardduedate}, 'iso' ),
262 $sampleissuingrule1->{rules}->{hardduedatecompare}
264 "GetHardDueDate returns the duedate and the duedatecompare"