View | Details | Raw Unified | Return to bug 27062
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Biblio.t (-11 / +6 lines)
Lines 189-195 subtest 'pickup_locations' => sub { Link Here
189
189
190
    $schema->storage->txn_begin;
190
    $schema->storage->txn_begin;
191
191
192
    my $nb_libraries = Koha::Libraries->count;
193
    Koha::CirculationRules->search->delete;
192
    Koha::CirculationRules->search->delete;
194
    Koha::CirculationRules->set_rules(
193
    Koha::CirculationRules->set_rules(
195
        {
194
        {
Lines 368-378 subtest 'pickup_locations' => sub { Link Here
368
    my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
367
    my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } );
369
368
370
    my $results = {
369
    my $results = {
371
        "ItemHomeLibrary-1-1" => 6  + $nb_libraries,
370
        "ItemHomeLibrary-1-1" => 6,
372
        "ItemHomeLibrary-1-8" => 1,
371
        "ItemHomeLibrary-1-8" => 1,
373
        "ItemHomeLibrary-2-1" => 2,
372
        "ItemHomeLibrary-2-1" => 2,
374
        "ItemHomeLibrary-2-8" => 0,
373
        "ItemHomeLibrary-2-8" => 0,
375
        "PatronLibrary-1-1" => 6 + $nb_libraries,
374
        "PatronLibrary-1-1" => 6,
376
        "PatronLibrary-1-8" => 3,
375
        "PatronLibrary-1-8" => 3,
377
        "PatronLibrary-2-1" => 0,
376
        "PatronLibrary-2-1" => 0,
378
        "PatronLibrary-2-8" => 3,
377
        "PatronLibrary-2-8" => 3,
Lines 382-395 subtest 'pickup_locations' => sub { Link Here
382
        my ( $cbranch, $biblio, $patron, $results ) = @_;
381
        my ( $cbranch, $biblio, $patron, $results ) = @_;
383
        t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
382
        t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch);
384
383
385
        my @pl = $biblio->pickup_locations( { patron => $patron } );
384
        my @pl = map {
386
385
            my $pickup_location = $_;
387
        foreach my $pickup_location (@pl) {
386
            grep { $pickup_location->branchcode eq $_ } @branchcodes
388
            next
387
        } $biblio->pickup_locations( { patron => $patron } )->as_list;
389
              unless grep { $pickup_location eq $_ } @branchcodes;
390
391
            is( ref($pickup_location), 'Koha::Library', 'Object type is correct' );
392
        }
393
388
394
        ok(
389
        ok(
395
            scalar(@pl) == $results->{ $cbranch . '-'
390
            scalar(@pl) == $results->{ $cbranch . '-'
(-)a/t/db_dependent/Koha/Item.t (-29 / +45 lines)
Lines 212-231 subtest 'pickup_locations' => sub { Link Here
212
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
212
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode, firstname => '1' } } );
213
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
213
    my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } );
214
214
215
    my $all_count = Koha::Libraries->search({ pickup_location => 1})->count();
216
217
    my $results = {
215
    my $results = {
218
        "1-1-1-any"           => $all_count,
216
        "1-1-1-any"           => 3,
219
        "1-1-1-holdgroup"     => 2,
217
        "1-1-1-holdgroup"     => 2,
220
        "1-1-1-patrongroup"   => 2,
218
        "1-1-1-patrongroup"   => 2,
221
        "1-1-1-homebranch"    => 1,
219
        "1-1-1-homebranch"    => 1,
222
        "1-1-1-holdingbranch" => 1,
220
        "1-1-1-holdingbranch" => 1,
223
        "1-1-2-any"           => $all_count,
221
        "1-1-2-any"           => 3,
224
        "1-1-2-holdgroup"     => 2,
222
        "1-1-2-holdgroup"     => 2,
225
        "1-1-2-patrongroup"   => 2,
223
        "1-1-2-patrongroup"   => 2,
226
        "1-1-2-homebranch"    => 1,
224
        "1-1-2-homebranch"    => 1,
227
        "1-1-2-holdingbranch" => 1,
225
        "1-1-2-holdingbranch" => 1,
228
        "1-1-3-any"           => $all_count,
226
        "1-1-3-any"           => 3,
229
        "1-1-3-holdgroup"     => 2,
227
        "1-1-3-holdgroup"     => 2,
230
        "1-1-3-patrongroup"   => 2,
228
        "1-1-3-patrongroup"   => 2,
231
        "1-1-3-homebranch"    => 1,
229
        "1-1-3-homebranch"    => 1,
Lines 235-241 subtest 'pickup_locations' => sub { Link Here
235
        "1-4-1-patrongroup"   => 0,
233
        "1-4-1-patrongroup"   => 0,
236
        "1-4-1-homebranch"    => 0,
234
        "1-4-1-homebranch"    => 0,
237
        "1-4-1-holdingbranch" => 0,
235
        "1-4-1-holdingbranch" => 0,
238
        "1-4-2-any"           => $all_count,
236
        "1-4-2-any"           => 3,
239
        "1-4-2-holdgroup"     => 2,
237
        "1-4-2-holdgroup"     => 2,
240
        "1-4-2-patrongroup"   => 1,
238
        "1-4-2-patrongroup"   => 1,
241
        "1-4-2-homebranch"    => 1,
239
        "1-4-2-homebranch"    => 1,
Lines 250-256 subtest 'pickup_locations' => sub { Link Here
250
        "3-1-1-patrongroup"   => 0,
248
        "3-1-1-patrongroup"   => 0,
251
        "3-1-1-homebranch"    => 0,
249
        "3-1-1-homebranch"    => 0,
252
        "3-1-1-holdingbranch" => 0,
250
        "3-1-1-holdingbranch" => 0,
253
        "3-1-2-any"           => $all_count,
251
        "3-1-2-any"           => 3,
254
        "3-1-2-holdgroup"     => 1,
252
        "3-1-2-holdgroup"     => 1,
255
        "3-1-2-patrongroup"   => 2,
253
        "3-1-2-patrongroup"   => 2,
256
        "3-1-2-homebranch"    => 0,
254
        "3-1-2-homebranch"    => 0,
Lines 265-276 subtest 'pickup_locations' => sub { Link Here
265
        "3-4-1-patrongroup"   => 0,
263
        "3-4-1-patrongroup"   => 0,
266
        "3-4-1-homebranch"    => 0,
264
        "3-4-1-homebranch"    => 0,
267
        "3-4-1-holdingbranch" => 0,
265
        "3-4-1-holdingbranch" => 0,
268
        "3-4-2-any"           => $all_count,
266
        "3-4-2-any"           => 3,
269
        "3-4-2-holdgroup"     => 1,
267
        "3-4-2-holdgroup"     => 1,
270
        "3-4-2-patrongroup"   => 1,
268
        "3-4-2-patrongroup"   => 1,
271
        "3-4-2-homebranch"    => 0,
269
        "3-4-2-homebranch"    => 0,
272
        "3-4-2-holdingbranch" => 1,
270
        "3-4-2-holdingbranch" => 1,
273
        "3-4-3-any"           => $all_count,
271
        "3-4-3-any"           => 3,
274
        "3-4-3-holdgroup"     => 1,
272
        "3-4-3-holdgroup"     => 1,
275
        "3-4-3-patrongroup"   => 1,
273
        "3-4-3-patrongroup"   => 1,
276
        "3-4-3-homebranch"    => 0,
274
        "3-4-3-homebranch"    => 0,
Lines 291-304 subtest 'pickup_locations' => sub { Link Here
291
                }
289
                }
292
            }
290
            }
293
        );
291
        );
294
        my @pl = $item->pickup_locations( { patron => $patron} )->as_list;
295
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
292
        my $ha_value=$ha==3?'holdgroup':($ha==2?'any':'homebranch');
296
293
297
        foreach my $pickup_location (@pl) {
294
        my @pl = map {
298
            next
295
            my $pickup_location = $_;
299
                unless grep { $pickup_location eq $_ } @branchcodes;
296
            grep { $pickup_location->branchcode eq $_ } @branchcodes
300
            is( ref($pickup_location), 'Koha::Library', 'Object type is correct' );
297
        } $item->pickup_locations( { patron => $patron } )->as_list;
301
        }
298
302
        ok(
299
        ok(
303
            scalar(@pl) == $results->{
300
            scalar(@pl) == $results->{
304
                    $item->copynumber . '-'
301
                    $item->copynumber . '-'
Lines 374-381 subtest 'pickup_locations' => sub { Link Here
374
        }
371
        }
375
    );
372
    );
376
373
377
    my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
374
    my @pickup_locations = map {
378
    is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
375
        my $pickup_location = $_;
376
        grep { $pickup_location->branchcode eq $_ } @branchcodes
377
    } $item1->pickup_locations( { patron => $patron1 } )->as_list;
378
379
    is( scalar @pickup_locations, 3 - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
379
380
380
    $builder->build_object(
381
    $builder->build_object(
381
        {
382
        {
Lines 389-403 subtest 'pickup_locations' => sub { Link Here
389
        }
390
        }
390
    );
391
    );
391
392
392
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
393
    @pickup_locations = map {
393
    is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
394
        my $pickup_location = $_;
395
        grep { $pickup_location->branchcode eq $_ } @branchcodes
396
    } $item1->pickup_locations( { patron => $patron1 } )->as_list;
394
397
395
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
398
    is( scalar @pickup_locations, 3 - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
396
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
397
    is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
398
399
399
    $pickup_locations = $item_no_ccode->pickup_locations( { patron => $patron1 } )->as_list;
400
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
400
    is( scalar @$pickup_locations, $all_count, "With no transfer limits of type ccode and an item with no ccode we get back the libraries that are pickup locations");
401
    @pickup_locations = map {
402
        my $pickup_location = $_;
403
        grep { $pickup_location->branchcode eq $_ } @branchcodes
404
    } $item1->pickup_locations( { patron => $patron1 } )->as_list;
405
    is( scalar @pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
406
407
    @pickup_locations = map {
408
        my $pickup_location = $_;
409
        grep { $pickup_location->branchcode eq $_ } @branchcodes
410
    } $item_no_ccode->pickup_locations( { patron => $patron1 } )->as_list;
411
    is( scalar @pickup_locations, 3, "With no transfer limits of type ccode and an item with no ccode we get back the libraries that are pickup locations");
401
412
402
    $builder->build_object(
413
    $builder->build_object(
403
        {
414
        {
Lines 411-418 subtest 'pickup_locations' => sub { Link Here
411
        }
422
        }
412
    );
423
    );
413
424
414
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
425
    @pickup_locations = map {
415
    is( scalar @$pickup_locations, $all_count - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
426
        my $pickup_location = $_;
427
        grep { $pickup_location->branchcode eq $_ } @branchcodes
428
    } $item1->pickup_locations( { patron => $patron1 } )->as_list;
429
    is( scalar @pickup_locations, 3 - 1, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
416
430
417
    $builder->build_object(
431
    $builder->build_object(
418
        {
432
        {
Lines 426-433 subtest 'pickup_locations' => sub { Link Here
426
        }
440
        }
427
    );
441
    );
428
442
429
    $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list;
443
    @pickup_locations = map {
430
    is( scalar @$pickup_locations, $all_count - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
444
        my $pickup_location = $_;
445
        grep { $pickup_location->branchcode eq $_ } @branchcodes
446
    } $item1->pickup_locations( { patron => $patron1 } )->as_list;
447
    is( scalar @pickup_locations, 3 - 2, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
431
448
432
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
449
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
433
450
434
- 

Return to bug 27062