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