|
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 89-95
my $item3 = $builder->build_sample_item(
Link Here
|
| 89 |
|
89 |
|
| 90 |
Koha::CirculationRules->delete(); |
90 |
Koha::CirculationRules->delete(); |
| 91 |
|
91 |
|
| 92 |
# Test GetMaxPatronHoldsForRecord and GetHoldRule |
92 |
# Test GetMaxPatronHoldsForRecord |
| 93 |
Koha::CirculationRules->set_rules( |
93 |
Koha::CirculationRules->set_rules( |
| 94 |
{ |
94 |
{ |
| 95 |
categorycode => undef, |
95 |
categorycode => undef, |
|
Lines 106-121
t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type
Link Here
|
| 106 |
|
106 |
|
| 107 |
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
107 |
my $max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 108 |
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
108 |
is( $max, 1, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
| 109 |
my $rule = C4::Reserves::GetHoldRule( |
|
|
| 110 |
$category->{categorycode}, |
| 111 |
$itemtype1->{itemtype}, |
| 112 |
$library->{branchcode} |
| 113 |
); |
| 114 |
is( $rule->{categorycode}, undef, 'Got rule with universal categorycode' ); |
| 115 |
is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' ); |
| 116 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
| 117 |
is( $rule->{reservesallowed}, 1, 'Got reservesallowed of 1' ); |
| 118 |
is( $rule->{holds_per_record}, 1, 'Got holds_per_record of 1' ); |
| 119 |
|
109 |
|
| 120 |
Koha::CirculationRules->set_rules( |
110 |
Koha::CirculationRules->set_rules( |
| 121 |
{ |
111 |
{ |
|
Lines 131-146
Koha::CirculationRules->set_rules(
Link Here
|
| 131 |
|
121 |
|
| 132 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
122 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 133 |
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' ); |
123 |
is( $max, 2, 'GetMaxPatronHoldsForRecord returns max of 2' ); |
| 134 |
$rule = C4::Reserves::GetHoldRule( |
|
|
| 135 |
$category->{categorycode}, |
| 136 |
$itemtype1->{itemtype}, |
| 137 |
$library->{branchcode} |
| 138 |
); |
| 139 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
| 140 |
is( $rule->{itemtype}, undef, 'Got rule with universal itemtype' ); |
| 141 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
| 142 |
is( $rule->{reservesallowed}, 2, 'Got reservesallowed of 2' ); |
| 143 |
is( $rule->{holds_per_record}, 2, 'Got holds_per_record of 2' ); |
| 144 |
|
124 |
|
| 145 |
Koha::CirculationRules->set_rules( |
125 |
Koha::CirculationRules->set_rules( |
| 146 |
{ |
126 |
{ |
|
Lines 156-171
Koha::CirculationRules->set_rules(
Link Here
|
| 156 |
|
136 |
|
| 157 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
137 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 158 |
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' ); |
138 |
is( $max, 3, 'GetMaxPatronHoldsForRecord returns max of 3' ); |
| 159 |
$rule = C4::Reserves::GetHoldRule( |
|
|
| 160 |
$category->{categorycode}, |
| 161 |
$itemtype1->{itemtype}, |
| 162 |
$library->{branchcode} |
| 163 |
); |
| 164 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
| 165 |
is( $rule->{itemtype}, $itemtype1->{itemtype}, 'Got rule with universal itemtype' ); |
| 166 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
| 167 |
is( $rule->{reservesallowed}, 3, 'Got reservesallowed of 3' ); |
| 168 |
is( $rule->{holds_per_record}, 3, 'Got holds_per_record of 3' ); |
| 169 |
|
139 |
|
| 170 |
Koha::CirculationRules->set_rules( |
140 |
Koha::CirculationRules->set_rules( |
| 171 |
{ |
141 |
{ |
|
Lines 181-196
Koha::CirculationRules->set_rules(
Link Here
|
| 181 |
|
151 |
|
| 182 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
152 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 183 |
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' ); |
153 |
is( $max, 4, 'GetMaxPatronHoldsForRecord returns max of 4' ); |
| 184 |
$rule = C4::Reserves::GetHoldRule( |
|
|
| 185 |
$category->{categorycode}, |
| 186 |
$itemtype2->{itemtype}, |
| 187 |
$library->{branchcode} |
| 188 |
); |
| 189 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
| 190 |
is( $rule->{itemtype}, $itemtype2->{itemtype}, 'Got rule with universal itemtype' ); |
| 191 |
is( $rule->{branchcode}, undef, 'Got rule with universal branchcode' ); |
| 192 |
is( $rule->{reservesallowed}, 4, 'Got reservesallowed of 4' ); |
| 193 |
is( $rule->{holds_per_record}, 4, 'Got holds_per_record of 4' ); |
| 194 |
|
154 |
|
| 195 |
Koha::CirculationRules->set_rules( |
155 |
Koha::CirculationRules->set_rules( |
| 196 |
{ |
156 |
{ |
|
Lines 205-221
Koha::CirculationRules->set_rules(
Link Here
|
| 205 |
); |
165 |
); |
| 206 |
|
166 |
|
| 207 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
167 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 208 |
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 1' ); |
168 |
is( $max, 5, 'GetMaxPatronHoldsForRecord returns max of 5' ); |
| 209 |
$rule = C4::Reserves::GetHoldRule( |
169 |
|
| 210 |
$category->{categorycode}, |
170 |
Koha::CirculationRules->set_rules( |
| 211 |
$itemtype2->{itemtype}, |
171 |
{ |
| 212 |
$library->{branchcode} |
172 |
categorycode => undef, |
|
|
173 |
itemtype => undef, |
| 174 |
branchcode => $library->{branchcode}, |
| 175 |
rules => { |
| 176 |
reservesallowed => 9, |
| 177 |
holds_per_record => 9, |
| 178 |
} |
| 179 |
} |
| 213 |
); |
180 |
); |
| 214 |
is( $rule->{categorycode}, $category->{categorycode}, 'Got rule with specific categorycode' ); |
181 |
|
| 215 |
is( $rule->{itemtype}, $itemtype2->{itemtype}, 'Got rule with universal itemtype' ); |
182 |
$max = GetMaxPatronHoldsForRecord( $patron->{borrowernumber}, $biblio->biblionumber ); |
| 216 |
is( $rule->{branchcode}, $library->{branchcode}, 'Got rule with specific branchcode' ); |
183 |
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' ); |
| 217 |
is( $rule->{reservesallowed}, 5, 'Got reservesallowed of 5' ); |
|
|
| 218 |
is( $rule->{holds_per_record}, 5, 'Got holds_per_record of 5' ); |
| 219 |
|
184 |
|
| 220 |
Koha::CirculationRules->delete(); |
185 |
Koha::CirculationRules->delete(); |
| 221 |
|
186 |
|
| 222 |
- |
|
|