From 580cf84a6f89241c6e81d233e71198d2bb99776f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 3 Jun 2020 16:58:25 -0300 Subject: [PATCH] Bug 25670: Unit tests --- t/db_dependent/Koha/Acquisition/Orders.t | 73 ++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 t/db_dependent/Koha/Acquisition/Orders.t diff --git a/t/db_dependent/Koha/Acquisition/Orders.t b/t/db_dependent/Koha/Acquisition/Orders.t new file mode 100644 index 00000000000..f4024c2ded2 --- /dev/null +++ b/t/db_dependent/Koha/Acquisition/Orders.t @@ -0,0 +1,73 @@ +#!/usr/bin/perl + +# Copyright 2020 Koha Development team +# +# 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 => 1; +use Test::Exception; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +use Koha::Database; + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'filter_by_id_including_transfers() tets' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $order_1 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + my $order_2 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + my $order_3 = $builder->build_object({ class => 'Koha::Acquisition::Orders' }); + + $builder->build( + { + source => 'AqordersTransfer', + value => { + ordernumber_from => $order_1->ordernumber, + ordernumber_to => $order_2->ordernumber + } + } + ); + + my $orders_rs = Koha::Acquisition::Orders->search; + my $count = $orders_rs->count; + + throws_ok + { $orders_rs->filter_by_id_including_transfers() } + 'Koha::Exceptions::MissingParameter', + 'Exception thrown correctly'; + + $orders_rs = $orders_rs->filter_by_id_including_transfers({ ordernumber => $order_1->ordernumber }); + + is( $orders_rs->count, 2, 'The two referenced orders are returned' ); + is( $orders_rs->next->ordernumber, $order_1->ordernumber, 'The right order is returned' ); + is( $orders_rs->next->ordernumber, $order_2->ordernumber, 'The right order is returned' ); + + $orders_rs = $orders_rs->filter_by_id_including_transfers({ ordernumber => $order_2->ordernumber }); + + is( $orders_rs->count, 1, 'Only one order related to the specified ordernumber' ); + is( $orders_rs->next->ordernumber, $order_2->ordernumber, 'The right order is returned' ); + + $schema->storage->txn_rollback; +} -- 2.26.2