From ba678553ce179760d21a900471ad90935c3c567b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 10 May 2021 10:11:19 +0100 Subject: [PATCH] Bug 24434: Unit tests for updateWrongTransfer Add unit tests to cover updateWrongTransfer Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Kyle M Hall Bug 24434: (QA follow-up) Remove tab character Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- circ/returns.pl | 2 +- t/db_dependent/Circulation.t | 42 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/circ/returns.pl b/circ/returns.pl index 3dd21de1b2..e456e531f2 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -405,7 +405,7 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { ); # Update the transfer to reflect the new item holdingbranch - my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch); + my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch); $template->param( NewTransfer => $new_transfer->id ); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 6266d14561..4ab64dd552 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 54; +use Test::More tests => 55; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -4879,6 +4879,46 @@ subtest "Item's onloan value should be set if checked out item is checked out to ok( $item->get_from_storage->onloan, "Item's onloan column is set after second checkout" ); }; +subtest "updateWrongTransfer tests" => sub { + plan tests => 5; + + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $item = $builder->build_sample_item( + { + homebranch => $library1->branchcode, + holdingbranch => $library2->branchcode, + datelastseen => undef + } + ); + + my $transfer = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item->itemnumber, + frombranch => $library2->branchcode, + tobranch => $library1->branchcode, + daterequested => dt_from_string, + datesent => dt_from_string, + datecancelled => undef, + datearrived => undef, + reason => 'Manual' + } + } + ); + is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' ); + + my $new_transfer = C4::Circulation::updateWrongTransfer($item->itemnumber, $library1->branchcode); + is(ref($new_transfer), 'Koha::Item::Transfer', "updateWrongTransfer returns a 'Koha::Item::Transfer' object"); + ok( !$new_transfer->in_transit, "New transfer is NOT created as in transit (or cancelled)"); + + my $original_transfer = $transfer->get_from_storage; + ok( defined($original_transfer->datecancelled), "Original transfer was cancelled"); + is( $original_transfer->cancellation_reason, 'WrongTransfer', "Original transfer cancellation reason is 'WrongTransfer'"); +}; + $schema->storage->txn_rollback; C4::Context->clear_syspref_cache(); $branches = Koha::Libraries->search(); -- 2.39.5