From a01b3fd916264947d3adb12f02d8ba759865f5ce Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Jun 2020 12:20:58 +0100 Subject: [PATCH] Bug 25767: Add unit tests for Koha::Item::Transfer->receipt Signed-off-by: Kathleen Milne Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Item/Transfer.t | 59 ++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item/Transfer.t b/t/db_dependent/Koha/Item/Transfer.t index 4b094d80cb..2814acec5c 100644 --- a/t/db_dependent/Koha/Item/Transfer.t +++ b/t/db_dependent/Koha/Item/Transfer.t @@ -23,7 +23,7 @@ use Koha::Database; use t::lib::TestBuilder; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; my $schema = Koha::Database->new->schema; @@ -112,3 +112,60 @@ subtest 'transit tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'receipt tests' => sub { + plan tests => 5; + + $schema->storage->txn_begin; + + my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library2 = $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, + datearrived => undef, + reason => 'Manual' + } + } + ); + is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' ); + + # Item checked out should result in failure + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts', + value => { + itemnumber => $item->itemnumber + } + } + ); + is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' ); + + throws_ok { $transfer->receipt() } + 'Koha::Exceptions::Item::Transfer::Out', + 'Exception thrown if item is checked out'; + + $checkout->delete; + + # Transit state set + $transfer->discard_changes; + $transfer->receipt(); + ok( $transfer->datearrived, 'Receipt set the datearrived for the transfer' ); + + # Last seen + ok( $item->datelastseen, 'Receipt set item datelastseen date' ); + + $schema->storage->txn_rollback; +}; -- 2.11.0