From 017b5f37ea15ab9aeb8cac0c2b9c08505a9a8304 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Sep 2020 14:56:23 +0100 Subject: [PATCH] Bug 25755: Add Unit tests for update get_transfer We updated Koha::Item->get_transfer here to account for the new daterequested field availability. It is now possible to set requested without setting datesent simultaneiously.. as such we need to update get_transfer to ensure we always return the right transfer (either the one 'in transit' or the oldest request first. This patch update the unit tests to test for this. Signed-off-by: Katrin Fischer --- Koha/Item.pm | 2 -- t/db_dependent/Koha/Items.t | 63 ++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 112e9b6b68..8d4ee142c1 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -459,8 +459,6 @@ Note: Transfers are retrieved in a Modified FIFO (First In First Out) order whereby the most recently sent, but not recieved, transfer will be returned if it exists, otherwise the oldest unsatisfied transfer will be returned. -FIXME: Add Tests for FIFO functionality - =cut sub get_transfer { diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 5cc3f3702e..978a257557 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -811,23 +811,72 @@ subtest 'store' => sub { }; subtest 'get_transfer' => sub { - plan tests => 3; + plan tests => 6; my $transfer = $new_item_1->get_transfer(); is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' ); my $library_to = $builder->build( { source => 'Branch' } ); - C4::Circulation::transferbook({ - from_branch => $new_item_1->holdingbranch, - to_branch => $library_to->{branchcode}, - barcode => $new_item_1->barcode, - }); + my $transfer_1 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $new_item_1->itemnumber, + frombranch => $new_item_1->holdingbranch, + tobranch => $library_to->{branchcode}, + reason => 'Manual', + datesent => undef, + datearrived => undef, + daterequested => \'NOW()' + } + } + ); $transfer = $new_item_1->get_transfer(); is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' ); - is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' ); + my $transfer_2 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $new_item_1->itemnumber, + frombranch => $new_item_1->holdingbranch, + tobranch => $library_to->{branchcode}, + reason => 'Manual', + datesent => undef, + datearrived => undef, + daterequested => \'NOW()' + } + } + ); + + $transfer = $new_item_1->get_transfer(); + is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the oldest transfer request'); + + $transfer_2->datesent(\'NOW()')->store; + $transfer = $new_item_1->get_transfer(); + is( $transfer->branchtransfer_id, $transfer_2->branchtransfer_id, 'Koha::Item->get_transfer returns the in_transit transfer'); + + my $transfer_3 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $new_item_1->itemnumber, + frombranch => $new_item_1->holdingbranch, + tobranch => $library_to->{branchcode}, + reason => 'Manual', + datesent => undef, + datearrived => undef, + daterequested => \'NOW()' + } + } + ); + + $transfer_2->datearrived(\'NOW()')->store; + $transfer = $new_item_1->get_transfer(); + is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the next queued transfer'); + is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' ); }; subtest 'holds' => sub { -- 2.28.0