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