From 89365159328446e2155ba9eccd6a4aa4d6de8d67 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 29 Mar 2023 11:44:56 +0200 Subject: [PATCH] Bug 11844: Add tests for TransferOrder Signed-off-by: Michaela Sieber Signed-off-by: Martin Renvoize --- Koha/Object/Mixin/AdditionalFields.pm | 1 + t/db_dependent/Acquisition/TransferOrder.t | 38 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm index 7990eba37c..bf6598d8c9 100644 --- a/Koha/Object/Mixin/AdditionalFields.pm +++ b/Koha/Object/Mixin/AdditionalFields.pm @@ -1,6 +1,7 @@ package Koha::Object::Mixin::AdditionalFields; use Modern::Perl; +use Koha::AdditionalFields; use Koha::AdditionalFieldValues; =head1 NAME diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index a9e59a5637..fc38127049 100755 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 14; use C4::Context; use C4::Acquisition qw( NewBasket GetOrders GetOrder TransferOrder SearchOrders ModReceiveOrder CancelReceipt ); use C4::Biblio; @@ -14,6 +14,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; use t::lib::TestBuilder; use MARC::Record; +use String::Random qw(random_string); my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); @@ -110,4 +111,39 @@ $order = GetOrder( $newordernumber ); is ( $order->{ordernumber}, $newordernumber, 'Regression test Bug 11549: After a transfer, receive and cancel the receive should be possible.' ); is ( $order->{basketno}, $basketno2, 'Regression test Bug 11549: The order still exist in the basket where the transfer has been done.'); +subtest 'TransferOrder should copy additional fields' => sub { + plan tests => 2; + + my $field = Koha::AdditionalField->new( + { + tablename => 'aqorders', + name => random_string('c' x 100), + } + ); + $field->store()->discard_changes(); + my $order = Koha::Acquisition::Order->new( + { + basketno => $basketno1, + quantity => 2, + biblionumber => $biblionumber, + budget_id => $budget->{budget_id}, + } + )->store; + $order->set_additional_fields( + [ + { + id => $field->id, + value => 'additional field value', + }, + ] + ); + + my $newordernumber = TransferOrder($order->ordernumber, $basketno2); + my $neworder = Koha::Acquisition::Orders->find($newordernumber); + my $field_values = $neworder->additional_field_values()->as_list; + + is(scalar @$field_values, 1, 'transfered order has one additional field value'); + is($field_values->[0]->value, 'additional field value', 'transfered order additional field has the correct value'); +}; + $schema->storage->txn_rollback(); -- 2.30.2