Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 40; |
22 |
use Test::More tests => 16; |
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
|
25 |
|
Lines 117-123
my $item3 = $builder->build(
Link Here
|
117 |
|
117 |
|
118 |
Koha::CirculationRules->delete(); |
118 |
Koha::CirculationRules->delete(); |
119 |
|
119 |
|
120 |
# Test GetMaxPatronHoldsForRecord and GetHoldRule |
120 |
# Test GetMaxPatronHoldsForRecord |
121 |
Koha::CirculationRules->set_rules( |
121 |
Koha::CirculationRules->set_rules( |
122 |
{ |
122 |
{ |
123 |
categorycode => undef, |
123 |
categorycode => undef, |
Lines 134-149
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type
Link Here
|
134 |
|
134 |
|
135 |
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
135 |
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
136 |
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
136 |
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
137 |
my $rule = C4::Reserves::GetHoldRule( |
|
|
138 |
$category->{categorycode}, |
139 |
$itemtype1->{itemtype}, |
140 |
$library->{branchcode} |
141 |
); |
142 |
is( $rule->{categorycode}, undef, 'Got rule with universal categorycode' ); |
143 |
is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' ); |
144 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
145 |
is( $rule->{reservesallowed}, 1, 'Got reservesallowed of 1' ); |
146 |
is( $rule->{holds_per_record}, 1, 'Got holds_per_record of 1' ); |
147 |
|
137 |
|
148 |
Koha::CirculationRules->set_rules( |
138 |
Koha::CirculationRules->set_rules( |
149 |
{ |
139 |
{ |
Lines 159-174
Koha::CirculationRules->set_rules(
Link Here
|
159 |
|
149 |
|
160 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
150 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
161 |
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' ); |
151 |
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' ); |
162 |
$rule = C4::Reserves::GetHoldRule( |
|
|
163 |
$category->{categorycode}, |
164 |
$itemtype1->{itemtype}, |
165 |
$library->{branchcode} |
166 |
); |
167 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
168 |
is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' ); |
169 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
170 |
is( $rule->{reservesallowed}, 2, 'Got reservesallowed of 2' ); |
171 |
is( $rule->{holds_per_record}, 2, 'Got holds_per_record of 2' ); |
172 |
|
152 |
|
173 |
Koha::CirculationRules->set_rules( |
153 |
Koha::CirculationRules->set_rules( |
174 |
{ |
154 |
{ |
Lines 184-199
Koha::CirculationRules->set_rules(
Link Here
|
184 |
|
164 |
|
185 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
165 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
186 |
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' ); |
166 |
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' ); |
187 |
$rule = C4::Reserves::GetHoldRule( |
|
|
188 |
$category->{categorycode}, |
189 |
$itemtype1->{itemtype}, |
190 |
$library->{branchcode} |
191 |
); |
192 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
193 |
is( $rule->{itemtype}, $itemtype1->{itemtype}, 'Got rule with universal itemtype' ); |
194 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
195 |
is( $rule->{reservesallowed}, 3, 'Got reservesallowed of 3' ); |
196 |
is( $rule->{holds_per_record}, 3, 'Got holds_per_record of 3' ); |
197 |
|
167 |
|
198 |
Koha::CirculationRules->set_rules( |
168 |
Koha::CirculationRules->set_rules( |
199 |
{ |
169 |
{ |
Lines 209-224
Koha::CirculationRules->set_rules(
Link Here
|
209 |
|
179 |
|
210 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
180 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
211 |
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' ); |
181 |
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' ); |
212 |
$rule = C4::Reserves::GetHoldRule( |
|
|
213 |
$category->{categorycode}, |
214 |
$itemtype2->{itemtype}, |
215 |
$library->{branchcode} |
216 |
); |
217 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
218 |
is( $rule->{itemtype}, $itemtype2->{itemtype}, 'Got rule with universal itemtype' ); |
219 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
220 |
is( $rule->{reservesallowed}, 4, 'Got reservesallowed of 4' ); |
221 |
is( $rule->{holds_per_record}, 4, 'Got holds_per_record of 4' ); |
222 |
|
182 |
|
223 |
Koha::CirculationRules->set_rules( |
183 |
Koha::CirculationRules->set_rules( |
224 |
{ |
184 |
{ |
Lines 233-249
Koha::CirculationRules->set_rules(
Link Here
|
233 |
); |
193 |
); |
234 |
|
194 |
|
235 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
195 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
236 |
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
196 |
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 5' ); |
237 |
$rule = C4::Reserves::GetHoldRule( |
197 |
|
238 |
$category->{categorycode}, |
198 |
Koha::CirculationRules->set_rules( |
239 |
$itemtype2->{itemtype}, |
199 |
{ |
240 |
$library->{branchcode} |
200 |
categorycode => undef, |
|
|
201 |
itemtype => undef, |
202 |
branchcode => $library->{branchcode}, |
203 |
rules => { |
204 |
reservesallowed => 9, |
205 |
holds_per_record => 9, |
206 |
} |
207 |
} |
241 |
); |
208 |
); |
242 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
209 |
|
243 |
is( $rule->{itemtype}, $itemtype2->{itemtype}, 'Got rule with universal itemtype' ); |
210 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->{biblionumber} ); |
244 |
is( $rule->{branchcode}, $library->{branchcode}, 'Got rule with specific branchcode' ); |
211 |
is( $max, 9, 'GetMaxPatronHoldsForRecord returns max of 9 because Library specific all itemtypes all categories rule comes before All libraries specific type and specific category' ); |
245 |
is( $rule->{reservesallowed}, 5, 'Got reservesallowed of 5' ); |
|
|
246 |
is( $rule->{holds_per_record}, 5, 'Got holds_per_record of 5' ); |
247 |
|
212 |
|
248 |
Koha::CirculationRules->delete(); |
213 |
Koha::CirculationRules->delete(); |
249 |
|
214 |
|
250 |
- |
|
|