Lines 757-763
subtest 'pickup_locations() tests' => sub {
Link Here
|
757 |
}; |
757 |
}; |
758 |
|
758 |
|
759 |
subtest 'request_transfer' => sub { |
759 |
subtest 'request_transfer' => sub { |
760 |
plan tests => 13; |
760 |
plan tests => 14; |
761 |
$schema->storage->txn_begin; |
761 |
$schema->storage->txn_begin; |
762 |
|
762 |
|
763 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
763 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
Lines 772-786
subtest 'request_transfer' => sub {
Link Here
|
772 |
# Mandatory fields tests |
772 |
# Mandatory fields tests |
773 |
throws_ok { $item->request_transfer( { to => $library1 } ) } |
773 |
throws_ok { $item->request_transfer( { to => $library1 } ) } |
774 |
'Koha::Exceptions::MissingParameter', |
774 |
'Koha::Exceptions::MissingParameter', |
775 |
'Exception thrown if `reason` parameter is missing'; |
775 |
'Exception thrown if `reason` parameter is missing'; |
776 |
|
776 |
|
777 |
throws_ok { $item->request_transfer( { reason => 'Manual' } ) } |
777 |
throws_ok { $item->request_transfer( { reason => 'Manual' } ) } |
778 |
'Koha::Exceptions::MissingParameter', |
778 |
'Koha::Exceptions::MissingParameter', |
779 |
'Exception thrown if `to` parameter is missing'; |
779 |
'Exception thrown if `to` parameter is missing'; |
780 |
|
780 |
|
781 |
# Successful request |
781 |
# Successful request |
782 |
my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' }); |
782 |
my $transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } ); |
783 |
is( ref($transfer), 'Koha::Item::Transfer', |
783 |
is( |
|
|
784 |
ref($transfer), 'Koha::Item::Transfer', |
784 |
'Koha::Item->request_transfer should return a Koha::Item::Transfer object' |
785 |
'Koha::Item->request_transfer should return a Koha::Item::Transfer object' |
785 |
); |
786 |
); |
786 |
my $original_transfer = $transfer->get_from_storage; |
787 |
my $original_transfer = $transfer->get_from_storage; |
Lines 788-837
subtest 'request_transfer' => sub {
Link Here
|
788 |
# Transfer already in progress |
789 |
# Transfer already in progress |
789 |
throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) } |
790 |
throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) } |
790 |
'Koha::Exceptions::Item::Transfer::InQueue', |
791 |
'Koha::Exceptions::Item::Transfer::InQueue', |
791 |
'Exception thrown if transfer is already in progress'; |
792 |
'Exception thrown if transfer is already in progress'; |
792 |
|
793 |
|
793 |
my $exception = $@; |
794 |
my $exception = $@; |
794 |
is( ref( $exception->transfer ), |
795 |
is( |
|
|
796 |
ref( $exception->transfer ), |
795 |
'Koha::Item::Transfer', |
797 |
'Koha::Item::Transfer', |
796 |
'The exception contains the found Koha::Item::Transfer' ); |
798 |
'The exception contains the found Koha::Item::Transfer' |
|
|
799 |
); |
797 |
|
800 |
|
798 |
# Queue transfer |
801 |
# Queue transfer |
799 |
my $queued_transfer = $item->request_transfer( |
802 |
my $queued_transfer = $item->request_transfer( { to => $library2, reason => 'Manual', enqueue => 1 } ); |
800 |
{ to => $library2, reason => 'Manual', enqueue => 1 } ); |
803 |
is( |
801 |
is( ref($queued_transfer), 'Koha::Item::Transfer', |
804 |
ref($queued_transfer), 'Koha::Item::Transfer', |
802 |
'Koha::Item->request_transfer allowed when enqueue is set' ); |
805 |
'Koha::Item->request_transfer allowed when enqueue is set' |
|
|
806 |
); |
803 |
my $transfers = $item->get_transfers; |
807 |
my $transfers = $item->get_transfers; |
804 |
is($transfers->count, 2, "There are now 2 live transfers in the queue"); |
808 |
is( $transfers->count, 2, "There are now 2 live transfers in the queue" ); |
805 |
$transfer = $transfer->get_from_storage; |
809 |
$transfer = $transfer->get_from_storage; |
806 |
is_deeply($transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged"); |
810 |
is_deeply( $transfer->unblessed, $original_transfer->unblessed, "Original transfer unchanged" ); |
807 |
$queued_transfer->datearrived(dt_from_string)->store(); |
811 |
$queued_transfer->datearrived(dt_from_string)->store(); |
808 |
|
812 |
|
809 |
# Replace transfer |
813 |
# Replace transfer |
810 |
my $replaced_transfer = $item->request_transfer( |
814 |
my $replaced_transfer = |
811 |
{ to => $library2, reason => 'Manual', replace => 1 } ); |
815 |
$item->request_transfer( { to => $library2, reason => 'Manual', replace => 'WrongTransfer' } ); |
812 |
is( ref($replaced_transfer), 'Koha::Item::Transfer', |
816 |
is( |
813 |
'Koha::Item->request_transfer allowed when replace is set' ); |
817 |
ref($replaced_transfer), 'Koha::Item::Transfer', |
|
|
818 |
'Koha::Item->request_transfer allowed when replace is set' |
819 |
); |
814 |
$original_transfer->discard_changes; |
820 |
$original_transfer->discard_changes; |
815 |
ok($original_transfer->datecancelled, "Original transfer cancelled"); |
821 |
ok( $original_transfer->datecancelled, "Original transfer cancelled" ); |
|
|
822 |
is( $original_transfer->cancellation_reason, "WrongTransfer", "Original cancellation_reason set correctly" ); |
816 |
$transfers = $item->get_transfers; |
823 |
$transfers = $item->get_transfers; |
817 |
is($transfers->count, 1, "There is only 1 live transfer in the queue"); |
824 |
is( $transfers->count, 1, "There is only 1 live transfer in the queue" ); |
818 |
$replaced_transfer->datearrived(dt_from_string)->store(); |
825 |
$replaced_transfer->datearrived(dt_from_string)->store(); |
819 |
|
826 |
|
820 |
# BranchTransferLimits |
827 |
# BranchTransferLimits |
821 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
828 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', 1 ); |
822 |
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); |
829 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
823 |
my $limit = Koha::Item::Transfer::Limit->new({ |
830 |
my $limit = Koha::Item::Transfer::Limit->new( |
824 |
fromBranch => $library2->branchcode, |
831 |
{ |
825 |
toBranch => $library1->branchcode, |
832 |
fromBranch => $library2->branchcode, |
826 |
itemtype => $item->effective_itemtype, |
833 |
toBranch => $library1->branchcode, |
827 |
})->store; |
834 |
itemtype => $item->effective_itemtype, |
|
|
835 |
} |
836 |
)->store; |
828 |
|
837 |
|
829 |
throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) } |
838 |
throws_ok { $item->request_transfer( { to => $library1, reason => 'Manual' } ) } |
830 |
'Koha::Exceptions::Item::Transfer::Limit', |
839 |
'Koha::Exceptions::Item::Transfer::Limit', |
831 |
'Exception thrown if transfer is prevented by limits'; |
840 |
'Exception thrown if transfer is prevented by limits'; |
832 |
|
841 |
|
833 |
my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } ); |
842 |
my $forced_transfer = $item->request_transfer( { to => $library1, reason => 'Manual', ignore_limits => 1 } ); |
834 |
is( ref($forced_transfer), 'Koha::Item::Transfer', |
843 |
is( |
|
|
844 |
ref($forced_transfer), 'Koha::Item::Transfer', |
835 |
'Koha::Item->request_transfer allowed when ignore_limits is set' |
845 |
'Koha::Item->request_transfer allowed when ignore_limits is set' |
836 |
); |
846 |
); |
837 |
|
847 |
|
838 |
- |
|
|