|
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 => 9; |
| 23 |
|
23 |
|
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 686-688
subtest 'suspend_hold() and resume() tests' => sub {
Link Here
|
| 686 |
|
686 |
|
| 687 |
$schema->storage->txn_rollback; |
687 |
$schema->storage->txn_rollback; |
| 688 |
}; |
688 |
}; |
| 689 |
- |
689 |
|
|
|
690 |
subtest 'cancellation_requests() and add_cancellation_request() tests' => sub { |
| 691 |
|
| 692 |
plan tests => 4; |
| 693 |
|
| 694 |
$schema->storage->txn_begin; |
| 695 |
|
| 696 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
| 697 |
|
| 698 |
my $hold = $builder->build_object( { class => 'Koha::Holds', } ); |
| 699 |
|
| 700 |
is( $hold->cancellation_requests->count, 0 ); |
| 701 |
|
| 702 |
# Add two cancellation requests |
| 703 |
my $request_1 = $hold->add_cancellation_request; |
| 704 |
isnt( $request_1->creation_date, undef, 'creation_date is set' ); |
| 705 |
|
| 706 |
my $requester = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 707 |
my $creation_date = '2021-06-25 14:05:35'; |
| 708 |
|
| 709 |
my $request_2 = $hold->add_cancellation_request( |
| 710 |
{ |
| 711 |
creation_date => $creation_date, |
| 712 |
} |
| 713 |
); |
| 714 |
|
| 715 |
is( $request_2->creation_date, $creation_date, 'Passed creation_date set' ); |
| 716 |
|
| 717 |
is( $hold->cancellation_requests->count, 2 ); |
| 718 |
|
| 719 |
$schema->storage->txn_rollback; |
| 720 |
}; |
| 721 |
|
| 722 |
subtest 'cancellation_requestable_from_opac() tests' => sub { |
| 723 |
|
| 724 |
plan tests => 5; |
| 725 |
|
| 726 |
$schema->storage->txn_begin; |
| 727 |
|
| 728 |
my $category = |
| 729 |
$builder->build_object( { class => 'Koha::Patron::Categories' } ); |
| 730 |
my $item_home_library = |
| 731 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
| 732 |
my $patron_home_library = |
| 733 |
$builder->build_object( { class => 'Koha::Libraries' } ); |
| 734 |
|
| 735 |
my $item = |
| 736 |
$builder->build_sample_item( { library => $item_home_library->id } ); |
| 737 |
my $patron = $builder->build_object( |
| 738 |
{ |
| 739 |
class => 'Koha::Patrons', |
| 740 |
value => { branchcode => $patron_home_library->id } |
| 741 |
} |
| 742 |
); |
| 743 |
|
| 744 |
subtest 'Exception cases' => sub { |
| 745 |
|
| 746 |
plan tests => 4; |
| 747 |
|
| 748 |
my $hold = $builder->build_object( |
| 749 |
{ |
| 750 |
class => 'Koha::Holds', |
| 751 |
value => { |
| 752 |
itemnumber => undef, |
| 753 |
found => undef, |
| 754 |
borrowernumber => $patron->id |
| 755 |
} |
| 756 |
} |
| 757 |
); |
| 758 |
|
| 759 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
| 760 |
'Koha::Exceptions::InvalidStatus', |
| 761 |
'Exception thrown because hold is not waiting'; |
| 762 |
|
| 763 |
is( $@->invalid_status, 'hold_not_waiting' ); |
| 764 |
|
| 765 |
$hold = $builder->build_object( |
| 766 |
{ |
| 767 |
class => 'Koha::Holds', |
| 768 |
value => { |
| 769 |
itemnumber => undef, |
| 770 |
found => 'W', |
| 771 |
borrowernumber => $patron->id |
| 772 |
} |
| 773 |
} |
| 774 |
); |
| 775 |
|
| 776 |
throws_ok { $hold->cancellation_requestable_from_opac; } |
| 777 |
'Koha::Exceptions::InvalidStatus', |
| 778 |
'Exception thrown because waiting hold has no item linked'; |
| 779 |
|
| 780 |
is( $@->invalid_status, 'no_item_linked' ); |
| 781 |
}; |
| 782 |
|
| 783 |
# set default rule to enabled |
| 784 |
Koha::CirculationRules->set_rule( |
| 785 |
{ |
| 786 |
categorycode => '*', |
| 787 |
itemtype => '*', |
| 788 |
branchcode => '*', |
| 789 |
rule_name => 'waiting_hold_cancellation', |
| 790 |
rule_value => 1, |
| 791 |
} |
| 792 |
); |
| 793 |
|
| 794 |
my $hold = $builder->build_object( |
| 795 |
{ |
| 796 |
class => 'Koha::Holds', |
| 797 |
value => { |
| 798 |
itemnumber => $item->id, |
| 799 |
found => 'W', |
| 800 |
borrowernumber => $patron->id |
| 801 |
} |
| 802 |
} |
| 803 |
); |
| 804 |
|
| 805 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', |
| 806 |
'ItemHomeLibrary' ); |
| 807 |
|
| 808 |
Koha::CirculationRules->set_rule( |
| 809 |
{ |
| 810 |
categorycode => $patron->categorycode, |
| 811 |
itemtype => $item->itype, |
| 812 |
branchcode => $item->homebranch, |
| 813 |
rule_name => 'waiting_hold_cancellation', |
| 814 |
rule_value => 0, |
| 815 |
} |
| 816 |
); |
| 817 |
|
| 818 |
ok( !$hold->cancellation_requestable_from_opac ); |
| 819 |
|
| 820 |
Koha::CirculationRules->set_rule( |
| 821 |
{ |
| 822 |
categorycode => $patron->categorycode, |
| 823 |
itemtype => $item->itype, |
| 824 |
branchcode => $item->homebranch, |
| 825 |
rule_name => 'waiting_hold_cancellation', |
| 826 |
rule_value => 1, |
| 827 |
} |
| 828 |
); |
| 829 |
|
| 830 |
ok( |
| 831 |
$hold->cancellation_requestable_from_opac, |
| 832 |
'Make sure it is picking the right circulation rule' |
| 833 |
); |
| 834 |
|
| 835 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
| 836 |
|
| 837 |
Koha::CirculationRules->set_rule( |
| 838 |
{ |
| 839 |
categorycode => $patron->categorycode, |
| 840 |
itemtype => $item->itype, |
| 841 |
branchcode => $patron->branchcode, |
| 842 |
rule_name => 'waiting_hold_cancellation', |
| 843 |
rule_value => 0, |
| 844 |
} |
| 845 |
); |
| 846 |
|
| 847 |
ok( !$hold->cancellation_requestable_from_opac ); |
| 848 |
|
| 849 |
Koha::CirculationRules->set_rule( |
| 850 |
{ |
| 851 |
categorycode => $patron->categorycode, |
| 852 |
itemtype => $item->itype, |
| 853 |
branchcode => $patron->branchcode, |
| 854 |
rule_name => 'waiting_hold_cancellation', |
| 855 |
rule_value => 1, |
| 856 |
} |
| 857 |
); |
| 858 |
|
| 859 |
ok( |
| 860 |
$hold->cancellation_requestable_from_opac, |
| 861 |
'Make sure it is picking the right circulation rule' |
| 862 |
); |
| 863 |
|
| 864 |
$schema->storage->txn_rollback; |
| 865 |
}; |