|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 12; |
20 |
use Test::More tests => 13; |
| 21 |
|
21 |
|
| 22 |
use C4::Biblio; |
22 |
use C4::Biblio; |
| 23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
Lines 569-571
subtest 'subscriptions() tests' => sub {
Link Here
|
| 569 |
|
569 |
|
| 570 |
$schema->storage->txn_rollback; |
570 |
$schema->storage->txn_rollback; |
| 571 |
}; |
571 |
}; |
|
|
572 |
|
| 573 |
subtest 'Recalls tests' => sub { |
| 574 |
|
| 575 |
plan tests => 12; |
| 576 |
|
| 577 |
$schema->storage->txn_begin; |
| 578 |
my $item1 = $builder->build_sample_item; |
| 579 |
my $biblio = $item1->biblio; |
| 580 |
my $branchcode = $item1->holdingbranch; |
| 581 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
| 582 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
| 583 |
my $patron3 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $branchcode } }); |
| 584 |
my $item2 = $builder->build_object({ class => 'Koha::Items', value => { holdingbranch => $branchcode, homebranch => $branchcode, biblionumber => $biblio->biblionumber, itype => $item1->effective_itemtype } }); |
| 585 |
t::lib::Mocks::mock_userenv({ patron => $patron1 }); |
| 586 |
|
| 587 |
my $recall1 = Koha::Recall->new({ |
| 588 |
borrowernumber => $patron1->borrowernumber, |
| 589 |
recalldate => Koha::DateUtils::dt_from_string, |
| 590 |
biblionumber => $biblio->biblionumber, |
| 591 |
branchcode => $branchcode, |
| 592 |
status => 'R', |
| 593 |
itemnumber => $item1->itemnumber, |
| 594 |
expirationdate => undef, |
| 595 |
item_level_recall => 1 |
| 596 |
})->store; |
| 597 |
my $recall2 = Koha::Recall->new({ |
| 598 |
borrowernumber => $patron2->borrowernumber, |
| 599 |
recalldate => Koha::DateUtils::dt_from_string, |
| 600 |
biblionumber => $biblio->biblionumber, |
| 601 |
branchcode => $branchcode, |
| 602 |
status => 'R', |
| 603 |
itemnumber => undef, |
| 604 |
expirationdate => undef, |
| 605 |
item_level_recall => 0 |
| 606 |
})->store; |
| 607 |
my $recall3 = Koha::Recall->new({ |
| 608 |
borrowernumber => $patron3->borrowernumber, |
| 609 |
recalldate => Koha::DateUtils::dt_from_string, |
| 610 |
biblionumber => $biblio->biblionumber, |
| 611 |
branchcode => $branchcode, |
| 612 |
status => 'R', |
| 613 |
itemnumber => $item1->itemnumber, |
| 614 |
expirationdate => undef, |
| 615 |
item_level_recall => 1 |
| 616 |
})->store; |
| 617 |
|
| 618 |
my $recalls_count = $biblio->recalls->count; |
| 619 |
is( $recalls_count, 3, 'Correctly get number of active recalls for biblio' ); |
| 620 |
|
| 621 |
$recall1->set_cancelled; |
| 622 |
$recall2->set_expired({ location => 'COMMANDLINE' }); |
| 623 |
|
| 624 |
$recalls_count = $biblio->recalls->count; |
| 625 |
is( $recalls_count, 1, 'Correctly get number of active recalls for biblio' ); |
| 626 |
|
| 627 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
| 628 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall with UseRecalls disabled" ); |
| 629 |
|
| 630 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
| 631 |
$item1->update({ notforloan => 1 }); |
| 632 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall with no available items" ); |
| 633 |
|
| 634 |
$item1->update({ notforloan => 0 }); |
| 635 |
Koha::CirculationRules->set_rules({ |
| 636 |
branchcode => $branchcode, |
| 637 |
categorycode => $patron1->categorycode, |
| 638 |
itemtype => $item1->effective_itemtype, |
| 639 |
rules => { |
| 640 |
recalls_allowed => 0, |
| 641 |
recalls_per_record => 1, |
| 642 |
on_shelf_recalls => 'all', |
| 643 |
}, |
| 644 |
}); |
| 645 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if recalls_allowed = 0" ); |
| 646 |
|
| 647 |
Koha::CirculationRules->set_rules({ |
| 648 |
branchcode => $branchcode, |
| 649 |
categorycode => $patron1->categorycode, |
| 650 |
itemtype => $item1->effective_itemtype, |
| 651 |
rules => { |
| 652 |
recalls_allowed => 1, |
| 653 |
recalls_per_record => 1, |
| 654 |
on_shelf_recalls => 'all', |
| 655 |
}, |
| 656 |
}); |
| 657 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_allowed" ); |
| 658 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has more existing recall(s) than recalls_per_record" ); |
| 659 |
|
| 660 |
$recall1->set_cancelled; |
| 661 |
C4::Circulation::AddIssue( $patron1->unblessed, $item2->barcode ); |
| 662 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if patron has already checked out an item attached to this biblio" ); |
| 663 |
|
| 664 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" ); |
| 665 |
|
| 666 |
Koha::CirculationRules->set_rules({ |
| 667 |
branchcode => $branchcode, |
| 668 |
categorycode => $patron1->categorycode, |
| 669 |
itemtype => $item1->effective_itemtype, |
| 670 |
rules => { |
| 671 |
recalls_allowed => 1, |
| 672 |
recalls_per_record => 1, |
| 673 |
on_shelf_recalls => 'any', |
| 674 |
}, |
| 675 |
}); |
| 676 |
C4::Circulation::AddReturn( $item2->barcode, $branchcode ); |
| 677 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if no items are checked out" ); |
| 678 |
|
| 679 |
$recall2->set_cancelled; |
| 680 |
C4::Circulation::AddIssue( $patron2->unblessed, $item2->barcode ); |
| 681 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 2, "Can recall two items" ); |
| 682 |
|
| 683 |
$item1->update({ withdrawn => 1 }); |
| 684 |
is( $biblio->can_be_recalled({ patron => $patron1 }), 1, "Can recall one item" ); |
| 685 |
|
| 686 |
$schema->storage->txn_rollback; |
| 687 |
}; |