8 use Koha::CirculationRules;
11 use t::lib::TestBuilder;
13 use Test::More tests => 10;
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 branchprinter => undef,
57 opac_info => 'sample opac',
61 branchname => 'Sample Branch2',
62 branchaddress1 => 'sample adr1_2',
63 branchaddress2 => 'sample adr2_2',
64 branchaddress3 => 'sample adr3_2',
65 branchzip => 'sample zip2',
66 branchcity => 'sample city2',
67 branchstate => 'sample state2',
68 branchcountry => 'sample country2',
69 branchphone => 'sample phone2',
70 branchfax => 'sample fax2',
71 branchemail => 'sample email2',
72 branchurl => 'sample url2',
73 branchip => 'sample ip2',
74 branchprinter => undef,
75 opac_info => 'sample opac2',
77 Koha::Library->new($samplebranch1)->store;
78 Koha::Library->new($samplebranch2)->store;
81 categorycode => 'CAT1',
82 description => 'Description1',
83 enrolmentperiod => undef,
84 enrolmentperioddate => undef,
85 dateofbirthrequired => undef,
88 enrolmentfee => undef,
89 overduenoticerequired => undef,
96 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
99 $samplecat->{categorycode}, $samplecat->{description},
100 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
101 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
102 $samplecat->{bulk}, $samplecat->{enrolmentfee},
103 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
104 $samplecat->{reservefee}, $samplecat->{hidelostitems},
105 $samplecat->{category_type}
108 my $builder = t::lib::TestBuilder->new;
109 my $sampleitemtype1 = $builder->build({ source => 'Itemtype' })->{itemtype};
110 my $sampleitemtype2 = $builder->build({ source => 'Itemtype' })->{itemtype};
120 #Test get_effective_rules
121 my $sampleissuingrule1 = {
122 branchcode => $samplebranch1->{branchcode},
123 categorycode => $samplecat->{categorycode},
124 itemtype => $sampleitemtype1,
127 lengthunit => 'days',
129 norenewalbefore => 6,
133 chargeperiod_charge_at => 0,
135 reservesallowed => 0,
136 hardduedate => '2013-01-01',
138 hardduedatecompare => 5,
139 overduefinescap => 0,
140 renewalsallowed => 0,
142 maxsuspensiondays => 0,
144 opacitemholds => 'N',
145 cap_fine_to_replacement_price => 0,
146 holds_per_record => 1,
147 article_requests => 'yes',
148 no_auto_renewal_after => undef,
149 no_auto_renewal_after_hard_limit => undef,
150 suspension_chargeperiod => 1,
151 holds_per_day => undef,
154 my $sampleissuingrule2 = {
155 branchcode => $samplebranch2->{branchcode},
156 categorycode => $samplecat->{categorycode},
157 itemtype => $sampleitemtype1,
159 renewalsallowed => 0,
161 norenewalbefore => 7,
163 reservesallowed => 0,
165 lengthunit => 'days',
167 hardduedatecompare => undef,
170 firstremind => undef,
171 chargeperiod => undef,
172 chargeperiod_charge_at => 0,
173 rentaldiscount => 2.00,
174 overduefinescap => 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},
186 itemtype => $sampleitemtype2,
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 maxsuspensiondays => 0,
206 opacitemholds => 'F',
207 cap_fine_to_replacement_price => 0,
208 holds_per_record => 1,
209 article_requests => 'yes',
213 Koha::CirculationRules->set_rules( $sampleissuingrule1 );
214 Koha::CirculationRules->set_rules( $sampleissuingrule2 );
215 Koha::CirculationRules->set_rules( $sampleissuingrule3 );
219 C4::Circulation::GetLoanLength(
220 $samplecat->{categorycode},
221 $sampleitemtype1, $samplebranch1->{branchcode}
223 { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
228 C4::Circulation::GetLoanLength(),
230 "Without parameters, GetLoanLength returns hardcoded values"
233 C4::Circulation::GetLoanLength( -1, -1 ),
235 "With wrong parameters, GetLoanLength returns hardcoded values"
238 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
240 "With only one parameter, GetLoanLength returns hardcoded values"
241 ); #NOTE : is that really what is expected?
243 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1 ),
245 "With only two parameters, GetLoanLength returns hardcoded values"
246 ); #NOTE : is that really what is expected?
248 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
252 lengthunit => 'days',
254 "With the correct number of parameters, GetLoanLength returns the expected values"
258 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
259 $sampleitemtype1, $samplebranch1->{branchcode} );
263 dt_from_string( $sampleissuingrule1->{rules}->{hardduedate}, 'iso' ),
264 $sampleissuingrule1->{rules}->{hardduedatecompare}
266 "GetHardDueDate returns the duedate and the duedatecompare"