|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 8; |
| 23 |
|
23 |
|
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 656-658
subtest 'suspend_hold() and resume() tests' => sub {
Link Here
|
| 656 |
|
656 |
|
| 657 |
$schema->storage->txn_rollback; |
657 |
$schema->storage->txn_rollback; |
| 658 |
}; |
658 |
}; |
| 659 |
- |
659 |
|
|
|
660 |
subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { |
| 661 |
|
| 662 |
plan tests => 8; |
| 663 |
|
| 664 |
$schema->storage->txn_begin; |
| 665 |
|
| 666 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
| 667 |
|
| 668 |
my $hold = $builder->build_object( { class => 'Koha::Holds', } ); |
| 669 |
|
| 670 |
is( $hold->cancellation_requests->count, 0 ); |
| 671 |
|
| 672 |
# Add two cancellation requests |
| 673 |
my $request_1 = $hold->add_cancellation_request; |
| 674 |
|
| 675 |
is( $request_1->requester_id, undef ); |
| 676 |
is( $request_1->status, 'requested', 'Default value set' ); |
| 677 |
isnt( $request_1->creation_date, undef ); |
| 678 |
|
| 679 |
my $requester = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 680 |
my $creation_date = '2021-06-25 14:05:35'; |
| 681 |
|
| 682 |
my $request_2 = $hold->add_cancellation_request( |
| 683 |
{ |
| 684 |
requester_id => $requester->id, |
| 685 |
creation_date => $creation_date, |
| 686 |
} |
| 687 |
); |
| 688 |
|
| 689 |
is( $request_2->requester_id, $requester->id, 'Passed requester_id set' ); |
| 690 |
is( $request_2->creation_date, $creation_date, 'Passed creation_date set' ); |
| 691 |
|
| 692 |
is( $hold->cancellation_requests->count, 2 ); |
| 693 |
|
| 694 |
subtest 'cancellation_requested_by_owner() tests' => sub { |
| 695 |
|
| 696 |
plan tests => 2; |
| 697 |
|
| 698 |
ok( !$hold->cancellation_requested_by_owner ); |
| 699 |
|
| 700 |
$hold->add_cancellation_request({ requester_id => $hold->borrowernumber }); |
| 701 |
|
| 702 |
ok( $hold->cancellation_requested_by_owner ); |
| 703 |
}; |
| 704 |
|
| 705 |
$schema->storage->txn_rollback; |
| 706 |
}; |
| 707 |
|
| 708 |
subtest 'cancellation_requestable_from_opac() tests' => sub { |
| 709 |
|
| 710 |
plan tests => 5; |
| 711 |
|
| 712 |
$schema->storage->txn_begin; |
| 713 |
|
| 714 |
my $category = |
| 715 |
$builder->build_object( { class => 'Koha::Patron::Categories' } ); |
| 716 |
my $item_home_library = |
| 717 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
| 718 |
my $patron_home_library = |
| 719 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
| 720 |
|
| 721 |
my $item = |
| 722 |
$builder->build_sample_item( { library => $item_home_library->id } ); |
| 723 |
my $patron = $builder->build_object( |
| 724 |
{ |
| 725 |
class => 'Koha::Patrons', |
| 726 |
value => { branchcode => $patron_home_library->id } |
| 727 |
} |
| 728 |
); |
| 729 |
|
| 730 |
subtest 'Exception cases' => sub { |
| 731 |
|
| 732 |
plan tests => 4; |
| 733 |
|
| 734 |
my $hold = $builder->build_object( |
| 735 |
{ |
| 736 |
class => 'Koha::Holds', |
| 737 |
value => { |
| 738 |
itemnumber => undef, |
| 739 |
found => undef, |
| 740 |
borrowernumber => $patron->id |
| 741 |
} |
| 742 |
} |
| 743 |
); |
| 744 |
|
| 745 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
| 746 |
'Koha::Exceptions::Hold::UnexpectedStatus', |
| 747 |
'Exception thrown because hold is not waiting'; |
| 748 |
|
| 749 |
is( "$@", "Cancellation can only be asked for waiting holds" ); |
| 750 |
|
| 751 |
$hold = $builder->build_object( |
| 752 |
{ |
| 753 |
class => 'Koha::Holds', |
| 754 |
value => { |
| 755 |
itemnumber => undef, |
| 756 |
found => 'W', |
| 757 |
borrowernumber => $patron->id |
| 758 |
} |
| 759 |
} |
| 760 |
); |
| 761 |
|
| 762 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
| 763 |
'Koha::Exceptions::Hold::UnexpectedStatus', |
| 764 |
'Exception thrown because waiting hold has no item linked'; |
| 765 |
|
| 766 |
is( "$@", "Waiting holds are expected to have an item linked" ); |
| 767 |
}; |
| 768 |
|
| 769 |
# set default rule to enabled |
| 770 |
Koha::CirculationRules->set_rule( |
| 771 |
{ |
| 772 |
categorycode => '*', |
| 773 |
itemtype => '*', |
| 774 |
branchcode => '*', |
| 775 |
rule_name => 'waiting_hold_cancellation', |
| 776 |
rule_value => 1, |
| 777 |
} |
| 778 |
); |
| 779 |
|
| 780 |
my $hold = $builder->build_object( |
| 781 |
{ |
| 782 |
class => 'Koha::Holds', |
| 783 |
value => { |
| 784 |
itemnumber => $item->id, |
| 785 |
found => 'W', |
| 786 |
borrowernumber => $patron->id |
| 787 |
} |
| 788 |
} |
| 789 |
); |
| 790 |
|
| 791 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', |
| 792 |
'ItemHomeLibrary' ); |
| 793 |
|
| 794 |
Koha::CirculationRules->set_rule( |
| 795 |
{ |
| 796 |
categorycode => $patron->categorycode, |
| 797 |
itemtype => $item->itype, |
| 798 |
branchcode => $item->homebranch, |
| 799 |
rule_name => 'waiting_hold_cancellation', |
| 800 |
rule_value => 0, |
| 801 |
} |
| 802 |
); |
| 803 |
|
| 804 |
ok( !$hold->cancellation_requestable_from_opac ); |
| 805 |
|
| 806 |
Koha::CirculationRules->set_rule( |
| 807 |
{ |
| 808 |
categorycode => $patron->categorycode, |
| 809 |
itemtype => $item->itype, |
| 810 |
branchcode => $item->homebranch, |
| 811 |
rule_name => 'waiting_hold_cancellation', |
| 812 |
rule_value => 1, |
| 813 |
} |
| 814 |
); |
| 815 |
|
| 816 |
ok( |
| 817 |
$hold->cancellation_requestable_from_opac, |
| 818 |
'Make sure it is picking the right circulation rule' |
| 819 |
); |
| 820 |
|
| 821 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
| 822 |
|
| 823 |
Koha::CirculationRules->set_rule( |
| 824 |
{ |
| 825 |
categorycode => $patron->categorycode, |
| 826 |
itemtype => $item->itype, |
| 827 |
branchcode => $patron->branchcode, |
| 828 |
rule_name => 'waiting_hold_cancellation', |
| 829 |
rule_value => 0, |
| 830 |
} |
| 831 |
); |
| 832 |
|
| 833 |
ok( !$hold->cancellation_requestable_from_opac ); |
| 834 |
|
| 835 |
Koha::CirculationRules->set_rule( |
| 836 |
{ |
| 837 |
categorycode => $patron->categorycode, |
| 838 |
itemtype => $item->itype, |
| 839 |
branchcode => $patron->branchcode, |
| 840 |
rule_name => 'waiting_hold_cancellation', |
| 841 |
rule_value => 1, |
| 842 |
} |
| 843 |
); |
| 844 |
|
| 845 |
ok( |
| 846 |
$hold->cancellation_requestable_from_opac, |
| 847 |
'Make sure it is picking the right circulation rule' |
| 848 |
); |
| 849 |
|
| 850 |
$schema->storage->txn_rollback; |
| 851 |
}; |