From abd1093e8a1658296a3858922a92e5a2c604d61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Tue, 2 Nov 2021 23:22:45 +0000 Subject: [PATCH] Bug 27708: (QA follow-up) Add a few tests for Koha::Edifact::Order 1. This adds a simple regression test to make sure order_line() method executes correctly with basket create_items set to "ordering" and "receiving". 2. A simple test for the filename method is added To test: 1) prove t/db_dependent/Koha/Edifact/Order.t --- t/db_dependent/Koha/Edifact/Order.t | 112 ++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 t/db_dependent/Koha/Edifact/Order.t diff --git a/t/db_dependent/Koha/Edifact/Order.t b/t/db_dependent/Koha/Edifact/Order.t new file mode 100755 index 0000000000..667e079638 --- /dev/null +++ b/t/db_dependent/Koha/Edifact/Order.t @@ -0,0 +1,112 @@ +#!/usr/bin/perl + +# Copyright 2021 Joonas Kylmälä +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 2; + +use Koha::Edifact::Order; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; + +my $builder = t::lib::TestBuilder->new; + +subtest 'order_line() tests' => sub { + # TODO: Split up order_line() to smaller methods in order + # to allow better testing + plan tests => 2; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio(); + my $ean = $builder->build( { source => 'EdifactEan' } ); + my $order = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { biblionumber => $biblio->biblionumber } + } + ); + + my $vendor = $builder->build( + { + source => 'VendorEdiAccount', + value => { + vendor_id => $order->basket->bookseller->id, + } + } + ); + + my @orders = $schema->resultset('Aqorder') + ->search( { basketno => $order->basket->basketno } )->all; + + my $edi_order = Koha::Edifact::Order->new( + { + orderlines => \@orders, + vendor => $vendor, + ean => $ean + } + ); + + $order->basket->create_items('ordering')->store; + + is( $edi_order->order_line( 1, $orders[0] ), + undef, 'Orderline message formed with with "ordering"' ); + + $order->basket->create_items('receiving')->store; + + is( $edi_order->order_line( 1, $orders[0] ), + undef, 'Orderline message formed with "receiving"' ); + + $schema->storage->txn_rollback; +}; + +subtest 'filename() tests' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + + my $ean = $builder->build( { source => 'EdifactEan' } ); + my $order = + $builder->build_object( { class => 'Koha::Acquisition::Orders' } ); + my $vendor = $builder->build( + { + source => 'VendorEdiAccount', + value => { vendor_id => $order->basket->bookseller->id } + } + ); + + my @orders = $schema->resultset('Aqorder') + ->search( { basketno => $order->basket->basketno } )->all; + + my $edi_order = Koha::Edifact::Order->new( + { + orderlines => \@orders, + vendor => $vendor, + ean => $ean + } + ); + + my $expected_filename = 'ordr' . $order->basket->basketno . '.CEP'; + is( $edi_order->filename, $expected_filename, + 'Filename is formed from the basket number' ); + + $schema->storage->txn_rollback; +}; -- 2.20.1