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