|
Lines 156-185
subtest "as_marc_field() tests" => sub {
Link Here
|
| 156 |
}; |
156 |
}; |
| 157 |
|
157 |
|
| 158 |
subtest 'pickup_locations' => sub { |
158 |
subtest 'pickup_locations' => sub { |
| 159 |
plan tests => 119; |
|
|
| 160 |
|
159 |
|
| 161 |
$schema->storage->txn_begin; |
160 |
$schema->storage->txn_begin; |
| 162 |
|
161 |
|
| 163 |
my $dbh = C4::Context->dbh; |
162 |
my $dbh = C4::Context->dbh; |
| 164 |
|
163 |
|
| 165 |
# Cleanup database |
|
|
| 166 |
Koha::Holds->search->delete; |
| 167 |
$dbh->do('DELETE FROM issues'); |
| 168 |
Koha::Patrons->search->delete; |
| 169 |
Koha::Items->search->delete; |
| 170 |
Koha::Libraries->search->delete; |
| 171 |
Koha::CirculationRules->search->delete; |
| 172 |
Koha::CirculationRules->set_rules( |
| 173 |
{ |
| 174 |
categorycode => undef, |
| 175 |
itemtype => undef, |
| 176 |
branchcode => undef, |
| 177 |
rules => { |
| 178 |
reservesallowed => 25, |
| 179 |
} |
| 180 |
} |
| 181 |
); |
| 182 |
|
| 183 |
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
164 |
my $root1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
| 184 |
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
165 |
my $root2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { ft_local_hold_group => 1, branchcode => undef } } ); |
| 185 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); |
166 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); |
|
Lines 192-204
subtest 'pickup_locations' => sub {
Link Here
|
| 192 |
my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
173 |
my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
| 193 |
my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
174 |
my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
| 194 |
|
175 |
|
| 195 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { itemtype => 'test' } } ); |
176 |
|
| 196 |
my $item1 = $builder->build_sample_item( |
177 |
my $item1 = $builder->build_sample_item( |
| 197 |
{ |
178 |
{ |
| 198 |
homebranch => $library1->branchcode, |
179 |
homebranch => $library1->branchcode, |
| 199 |
holdingbranch => $library2->branchcode, |
180 |
holdingbranch => $library2->branchcode, |
| 200 |
barcode => '1', |
181 |
barcode => '1', |
| 201 |
itype => 'test', |
|
|
| 202 |
ccode => 'Gollum' |
182 |
ccode => 'Gollum' |
| 203 |
} |
183 |
} |
| 204 |
)->store; |
184 |
)->store; |
|
Lines 208-232
subtest 'pickup_locations' => sub {
Link Here
|
| 208 |
homebranch => $library3->branchcode, |
188 |
homebranch => $library3->branchcode, |
| 209 |
holdingbranch => $library4->branchcode, |
189 |
holdingbranch => $library4->branchcode, |
| 210 |
barcode => '3', |
190 |
barcode => '3', |
| 211 |
itype => 'test', |
191 |
itype => $item1->itype, |
| 212 |
} |
192 |
} |
| 213 |
)->store; |
193 |
)->store; |
| 214 |
|
194 |
|
|
|
195 |
Koha::CirculationRules->set_rules( |
| 196 |
{ |
| 197 |
categorycode => undef, |
| 198 |
itemtype => $item1->itype, |
| 199 |
branchcode => undef, |
| 200 |
rules => { |
| 201 |
reservesallowed => 25, |
| 202 |
} |
| 203 |
} |
| 204 |
); |
| 205 |
|
| 206 |
|
| 215 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } ); |
207 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } ); |
| 216 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } ); |
208 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } ); |
| 217 |
|
209 |
|
|
|
210 |
my $all_count = Koha::Libraries->search({ pickup_location => 1})->count(); |
| 211 |
plan tests => ($all_count +1) * 7 + 31 + 60; |
| 212 |
|
| 218 |
my $results = { |
213 |
my $results = { |
| 219 |
"1-1-1-any" => 3, |
214 |
"1-1-1-any" => $all_count, |
| 220 |
"1-1-1-holdgroup" => 2, |
215 |
"1-1-1-holdgroup" => 2, |
| 221 |
"1-1-1-patrongroup" => 2, |
216 |
"1-1-1-patrongroup" => 2, |
| 222 |
"1-1-1-homebranch" => 1, |
217 |
"1-1-1-homebranch" => 1, |
| 223 |
"1-1-1-holdingbranch" => 1, |
218 |
"1-1-1-holdingbranch" => 1, |
| 224 |
"1-1-2-any" => 3, |
219 |
"1-1-2-any" => $all_count, |
| 225 |
"1-1-2-holdgroup" => 2, |
220 |
"1-1-2-holdgroup" => 2, |
| 226 |
"1-1-2-patrongroup" => 2, |
221 |
"1-1-2-patrongroup" => 2, |
| 227 |
"1-1-2-homebranch" => 1, |
222 |
"1-1-2-homebranch" => 1, |
| 228 |
"1-1-2-holdingbranch" => 1, |
223 |
"1-1-2-holdingbranch" => 1, |
| 229 |
"1-1-3-any" => 3, |
224 |
"1-1-3-any" => $all_count, |
| 230 |
"1-1-3-holdgroup" => 2, |
225 |
"1-1-3-holdgroup" => 2, |
| 231 |
"1-1-3-patrongroup" => 2, |
226 |
"1-1-3-patrongroup" => 2, |
| 232 |
"1-1-3-homebranch" => 1, |
227 |
"1-1-3-homebranch" => 1, |
|
Lines 236-242
subtest 'pickup_locations' => sub {
Link Here
|
| 236 |
"1-4-1-patrongroup" => 0, |
231 |
"1-4-1-patrongroup" => 0, |
| 237 |
"1-4-1-homebranch" => 0, |
232 |
"1-4-1-homebranch" => 0, |
| 238 |
"1-4-1-holdingbranch" => 0, |
233 |
"1-4-1-holdingbranch" => 0, |
| 239 |
"1-4-2-any" => 3, |
234 |
"1-4-2-any" => $all_count, |
| 240 |
"1-4-2-holdgroup" => 2, |
235 |
"1-4-2-holdgroup" => 2, |
| 241 |
"1-4-2-patrongroup" => 1, |
236 |
"1-4-2-patrongroup" => 1, |
| 242 |
"1-4-2-homebranch" => 1, |
237 |
"1-4-2-homebranch" => 1, |
|
Lines 251-257
subtest 'pickup_locations' => sub {
Link Here
|
| 251 |
"3-1-1-patrongroup" => 0, |
246 |
"3-1-1-patrongroup" => 0, |
| 252 |
"3-1-1-homebranch" => 0, |
247 |
"3-1-1-homebranch" => 0, |
| 253 |
"3-1-1-holdingbranch" => 0, |
248 |
"3-1-1-holdingbranch" => 0, |
| 254 |
"3-1-2-any" => 3, |
249 |
"3-1-2-any" => $all_count, |
| 255 |
"3-1-2-holdgroup" => 1, |
250 |
"3-1-2-holdgroup" => 1, |
| 256 |
"3-1-2-patrongroup" => 2, |
251 |
"3-1-2-patrongroup" => 2, |
| 257 |
"3-1-2-homebranch" => 0, |
252 |
"3-1-2-homebranch" => 0, |
|
Lines 266-277
subtest 'pickup_locations' => sub {
Link Here
|
| 266 |
"3-4-1-patrongroup" => 0, |
261 |
"3-4-1-patrongroup" => 0, |
| 267 |
"3-4-1-homebranch" => 0, |
262 |
"3-4-1-homebranch" => 0, |
| 268 |
"3-4-1-holdingbranch" => 0, |
263 |
"3-4-1-holdingbranch" => 0, |
| 269 |
"3-4-2-any" => 3, |
264 |
"3-4-2-any" => $all_count, |
| 270 |
"3-4-2-holdgroup" => 1, |
265 |
"3-4-2-holdgroup" => 1, |
| 271 |
"3-4-2-patrongroup" => 1, |
266 |
"3-4-2-patrongroup" => 1, |
| 272 |
"3-4-2-homebranch" => 0, |
267 |
"3-4-2-homebranch" => 0, |
| 273 |
"3-4-2-holdingbranch" => 1, |
268 |
"3-4-2-holdingbranch" => 1, |
| 274 |
"3-4-3-any" => 3, |
269 |
"3-4-3-any" => $all_count, |
| 275 |
"3-4-3-holdgroup" => 1, |
270 |
"3-4-3-holdgroup" => 1, |
| 276 |
"3-4-3-patrongroup" => 1, |
271 |
"3-4-3-patrongroup" => 1, |
| 277 |
"3-4-3-homebranch" => 0, |
272 |
"3-4-3-homebranch" => 0, |
|
Lines 365-371
subtest 'pickup_locations' => sub {
Link Here
|
| 365 |
); |
360 |
); |
| 366 |
|
361 |
|
| 367 |
my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
362 |
my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 368 |
is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
363 |
is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
| 369 |
|
364 |
|
| 370 |
$builder->build_object( |
365 |
$builder->build_object( |
| 371 |
{ |
366 |
{ |
|
Lines 380-390
subtest 'pickup_locations' => sub {
Link Here
|
| 380 |
); |
375 |
); |
| 381 |
|
376 |
|
| 382 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
377 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 383 |
is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
378 |
is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
| 384 |
|
379 |
|
| 385 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); |
380 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); |
| 386 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
381 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 387 |
is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations"); |
382 |
is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations"); |
| 388 |
|
383 |
|
| 389 |
$builder->build_object( |
384 |
$builder->build_object( |
| 390 |
{ |
385 |
{ |
|
Lines 399-405
subtest 'pickup_locations' => sub {
Link Here
|
| 399 |
); |
394 |
); |
| 400 |
|
395 |
|
| 401 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
396 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 402 |
is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
397 |
is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); |
| 403 |
|
398 |
|
| 404 |
$builder->build_object( |
399 |
$builder->build_object( |
| 405 |
{ |
400 |
{ |
|
Lines 414-420
subtest 'pickup_locations' => sub {
Link Here
|
| 414 |
); |
409 |
); |
| 415 |
|
410 |
|
| 416 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
411 |
$pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; |
| 417 |
is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
412 |
is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); |
| 418 |
|
413 |
|
| 419 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); |
414 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); |
| 420 |
|
415 |
|
| 421 |
- |
|
|