From e3a7ee705cf75f866efd06fe4a5760e84d81c493 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 --- t/db_dependent/Circulation.t | 42 +++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) 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.20.1