|
Lines 846-852
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 846 |
}; |
846 |
}; |
| 847 |
|
847 |
|
| 848 |
subtest 'request_transfer' => sub { |
848 |
subtest 'request_transfer' => sub { |
| 849 |
plan tests => 13; |
849 |
plan tests => 14; |
| 850 |
$schema->storage->txn_begin; |
850 |
$schema->storage->txn_begin; |
| 851 |
|
851 |
|
| 852 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
852 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
|
Lines 861-875
subtest 'request_transfer' => sub {
Link Here
|
| 861 |
# Mandatory fields tests |
861 |
# Mandatory fields tests |
| 862 |
throws_ok { $item->request_transfer( { to => $library1 } ) } |
862 |
throws_ok { $item->request_transfer( { to => $library1 } ) } |
| 863 |
'Koha::Exceptions::MissingParameter', |
863 |
'Koha::Exceptions::MissingParameter', |
| 864 |
'Exception thrown if `reason` parameter is missing'; |
864 |
'Exception thrown if `reason` parameter is missing'; |
| 865 |
|
865 |
|
| 866 |
throws_ok { $item->request_transfer( { reason => 'Manual' } ) } |
866 |
throws_ok { $item->request_transfer( { reason => 'Manual' } ) } |
| 867 |
'Koha::Exceptions::MissingParameter', |
867 |
'Koha::Exceptions::MissingParameter', |
| 868 |
'Exception thrown if `to` parameter is missing'; |
868 |
'Exception thrown if `to` parameter is missing'; |
| 869 |
|
869 |
|
| 870 |
# Successful request |
870 |
# Successful request |
| 871 |
my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' }); |
871 |
my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } ); |
| 872 |
is( ref($transfer), 'Koha::Item::Transfer', |
872 |
is( |
|
|
873 |
ref($transfer), 'Koha::Item::Transfer', |
| 873 |
'Koha::Item->request_transfer should return a Koha::Item::Transfer object' |
874 |
'Koha::Item->request_transfer should return a Koha::Item::Transfer object' |
| 874 |
); |
875 |
); |
| 875 |
my $original_transfer = $transfer->get_from_storage; |
876 |
my $original_transfer = $transfer->get_from_storage; |
|
Lines 877-926
subtest 'request_transfer' => sub {
Link Here
|
| 877 |
# Transfer already in progress |
878 |
# Transfer already in progress |
| 878 |
throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) } |
879 |
throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) } |
| 879 |
'Koha::Exceptions::Item::Transfer::InQueue', |
880 |
'Koha::Exceptions::Item::Transfer::InQueue', |
| 880 |
'Exception thrown if transfer is already in progress'; |
881 |
'Exception thrown if transfer is already in progress'; |
| 881 |
|
882 |
|
| 882 |
my $exception = $@; |
883 |
my $exception = $@; |
| 883 |
is( ref( $exception->transfer ), |
884 |
is( |
|
|
885 |
ref( $exception->transfer ), |
| 884 |
'Koha::Item::Transfer', |
886 |
'Koha::Item::Transfer', |
| 885 |
'The exception contains the found Koha::Item::Transfer' ); |
887 |
'The exception contains the found Koha::Item::Transfer' |
|
|
888 |
); |
| 886 |
|
889 |
|
| 887 |
# Queue transfer |
890 |
# Queue transfer |
| 888 |
my $queued_transfer = $item->request_transfer( |
891 |
my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } ); |
| 889 |
{ to => $library2, reason => 'Manual', enqueue => 1 } ); |
892 |
is( |
| 890 |
is( ref($queued_transfer), 'Koha::Item::Transfer', |
893 |
ref($queued_transfer), 'Koha::Item::Transfer', |
| 891 |
'Koha::Item->request_transfer allowed when enqueue is set' ); |
894 |
'Koha::Item->request_transfer allowed when enqueue is set' |
|
|
895 |
); |
| 892 |
my $transfers = $item->get_transfers; |
896 |
my $transfers = $item->get_transfers; |
| 893 |
is($transfers->count, 2, "There are now 2 live transfers in the queue"); |
897 |
is( $transfers->count, 2, "There are now 2 live transfers in the queue" ); |
| 894 |
$transfer = $transfer->get_from_storage; |
898 |
$transfer = $transfer->get_from_storage; |
| 895 |
is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged"); |
899 |
is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" ); |
| 896 |
$queued_transfer->datearrived(dt_from_string)->store(); |
900 |
$queued_transfer->datearrived(dt_from_string)->store(); |
| 897 |
|
901 |
|
| 898 |
# Replace transfer |
902 |
# Replace transfer |
| 899 |
my $replaced_transfer = $item->request_transfer( |
903 |
my $replaced_transfer = |
| 900 |
{ to => $library2, reason => 'Manual', replace => 1 } ); |
904 |
$item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } ); |
| 901 |
is( ref($replaced_transfer), 'Koha::Item::Transfer', |
905 |
is( |
| 902 |
'Koha::Item->request_transfer allowed when replace is set' ); |
906 |
ref($replaced_transfer), 'Koha::Item::Transfer', |
|
|
907 |
'Koha::Item->request_transfer allowed when replace is set' |
| 908 |
); |
| 903 |
$original_transfer->discard_changes; |
909 |
$original_transfer->discard_changes; |
| 904 |
ok($original_transfer->datecancelled, "Original transfer cancelled"); |
910 |
ok( $original_transfer->datecancelled, "Original transfer cancelled" ); |
|
|
911 |
is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" ); |
| 905 |
$transfers = $item->get_transfers; |
912 |
$transfers = $item->get_transfers; |
| 906 |
is($transfers->count, 1, "There is only 1 live transfer in the queue"); |
913 |
is( $transfers->count, 1, "There is only 1 live transfer in the queue" ); |
| 907 |
$replaced_transfer->datearrived(dt_from_string)->store(); |
914 |
$replaced_transfer->datearrived(dt_from_string)->store(); |
| 908 |
|
915 |
|
| 909 |
# BranchTransferLimits |
916 |
# BranchTransferLimits |
| 910 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
917 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', 1 ); |
| 911 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
918 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 912 |
my $limit = Koha::Item::Transfer::Limit->new({ |
919 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 913 |
fromBranch => $library2->branchcode, |
920 |
{ |
| 914 |
toBranch => $library1->branchcode, |
921 |
fromBranch => $library2->branchcode, |
| 915 |
itemtype => $item->effective_itemtype, |
922 |
toBranch => $library1->branchcode, |
| 916 |
})->store; |
923 |
itemtype => $item->effective_itemtype, |
|
|
924 |
} |
| 925 |
)->store; |
| 917 |
|
926 |
|
| 918 |
throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) } |
927 |
throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) } |
| 919 |
'Koha::Exceptions::Item::Transfer::Limit', |
928 |
'Koha::Exceptions::Item::Transfer::Limit', |
| 920 |
'Exception thrown if transfer is prevented by limits'; |
929 |
'Exception thrown if transfer is prevented by limits'; |
| 921 |
|
930 |
|
| 922 |
my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } ); |
931 |
my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } ); |
| 923 |
is( ref($forced_transfer), 'Koha::Item::Transfer', |
932 |
is( |
|
|
933 |
ref($forced_transfer), 'Koha::Item::Transfer', |
| 924 |
'Koha::Item->request_transfer allowed when ignore_limits is set' |
934 |
'Koha::Item->request_transfer allowed when ignore_limits is set' |
| 925 |
); |
935 |
); |
| 926 |
|
936 |
|
| 927 |
- |
|
|