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

(-)a/t/db_dependent/Koha/Item.t (-2 / +85 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
23
24
use C4::Biblio;
24
use C4::Biblio;
25
use C4::Circulation;
25
use C4::Circulation;
Lines 339-344 subtest 'pickup_locations' => sub { Link Here
339
    $schema->storage->txn_rollback;
339
    $schema->storage->txn_rollback;
340
};
340
};
341
341
342
subtest '_can_pickup_at' => sub {
343
    plan tests =>8;
344
345
    $schema->storage->txn_begin;
346
347
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
348
349
    my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
350
    my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
351
    my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } );
352
    my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } );
353
354
    my $item = $builder->build_sample_item({
355
        homebranch => $library1->branchcode,
356
        holdingbranch => $library1->branchcode,
357
        ccode => "Gollum"
358
    });
359
360
    my @to = ( $library1, $library2, $library3, $library4 );
361
362
    my $pickup_locations = $item->_can_pickup_at({ to => \@to });
363
    is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations");
364
365
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
366
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
367
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
368
        toBranch => $library2->branchcode,
369
        fromBranch => $library1->branchcode,
370
        itemtype => $item->itype,
371
        ccode => undef,
372
        }
373
    });
374
375
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
376
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
377
378
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
379
        toBranch => $library4->branchcode,
380
        fromBranch => $library1->branchcode,
381
        itemtype => $item->itype,
382
        ccode => undef,
383
        }
384
    });
385
386
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
387
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
388
389
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode');
390
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
391
    is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations");
392
393
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
394
        toBranch => $library2->branchcode,
395
        fromBranch => $library1->branchcode,
396
        itemtype => undef,
397
        ccode => $item->ccode,
398
        }
399
    });
400
401
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
402
    is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library");
403
404
    $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => {
405
        toBranch => $library4->branchcode,
406
        fromBranch => $library1->branchcode,
407
        itemtype => undef,
408
        ccode => $item->ccode,
409
        }
410
    });
411
412
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
413
    is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries");
414
415
416
    $pickup_locations = $item->_can_pickup_at({ to => \@to, from => $library2 });
417
    is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations");
418
419
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0);
420
421
    $pickup_locations = $item->_can_pickup_at({ to => \@to });
422
    is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations");
423
424
};
425
342
subtest 'deletion' => sub {
426
subtest 'deletion' => sub {
343
    plan tests => 12;
427
    plan tests => 12;
344
428
345
- 

Return to bug 26963