From dc4e072039c127d28554d46a3f1cbe6dac921d91 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 2 Apr 2019 18:02:14 +0000 Subject: [PATCH] Bug 22618: Move tests to t/db_dependent/Acquisition.t prove -v t/db_dependent/Acquisition.t Signed-off-by: Michal Denar Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens (cherry picked from commit ea3cbef473a8b542b58341ef38beb9f7be20f4a1) Signed-off-by: Martin Renvoize --- t/Acquisition.t | 68 ------------------------------ t/db_dependent/Acquisition.t | 80 +++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 69 deletions(-) delete mode 100644 t/Acquisition.t diff --git a/t/Acquisition.t b/t/Acquisition.t deleted file mode 100644 index 9c5102c9b1..0000000000 --- a/t/Acquisition.t +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Copyright (C) 2018 Mark Tompsett -# -# 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 => 3; -use t::lib::Mocks; - -use_ok( 'C4::Acquisition' ); - -subtest 'Tests for get_rounding_sql' => sub { - - plan tests => 2; - - my $value = '3.141592'; - - t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} ); - my $no_rounding_result = C4::Acquisition::get_rounding_sql($value); - t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} ); - my $rounding_result = C4::Acquisition::get_rounding_sql($value); - - ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" ); - ok( $rounding_result =~ /CAST/, "Value ($value) will be rounded" ); - -}; - -subtest 'Test for get_rounded_price' => sub { - - plan tests => 6; - - my $exact_price = 3.14; - my $up_price = 3.145592; - my $down_price = 3.141592; - my $round_up_price = sprintf( '%0.2f', $up_price ); - my $round_down_price = sprintf( '%0.2f', $down_price ); - - t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} ); - my $not_rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); - my $not_rounded_result2 = C4::Acquisition::get_rounded_price($up_price); - my $not_rounded_result3 = C4::Acquisition::get_rounded_price($down_price); - t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} ); - my $rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); - my $rounded_result2 = C4::Acquisition::get_rounded_price($up_price); - my $rounded_result3 = C4::Acquisition::get_rounded_price($down_price); - - is( $not_rounded_result1, $exact_price, "Price ($exact_price) was correctly not rounded ($not_rounded_result1)" ); - is( $not_rounded_result2, $up_price, "Price ($up_price) was correctly not rounded ($not_rounded_result2)" ); - is( $not_rounded_result3, $down_price, "Price ($down_price) was correctly not rounded ($not_rounded_result3)" ); - is( $rounded_result1, $exact_price, "Price ($exact_price) was correctly rounded ($rounded_result1)" ); - is( $rounded_result2, $round_up_price, "Price ($up_price) was correctly rounded ($rounded_result2)" ); - is( $rounded_result3, $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" ); - -}; diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 691a0a8a70..4211c0809f 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -19,7 +19,7 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 74; +use Test::More tests => 76; use t::lib::Mocks; use Koha::Database; @@ -759,4 +759,82 @@ subtest 'ModReceiveOrder and subscription' => sub { is( $order->get_from_storage->order_internalnote, $first_note ); }; +subtest 'GetHistory with additional fields' => sub { + plan tests => 3; + my $builder = t::lib::TestBuilder->new; + my $order_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } }); + my $orderinfo ={ + basketno => $order_basket->{basketno}, + rrp => 19.99, + replacementprice => undef, + quantity => 1, + quantityreceived => 0, + datereceived => undef, + datecancellationprinted => undef, + }; + my $order = $builder->build({ source => 'Aqorder', value => $orderinfo }); + my $history = GetHistory(ordernumber => $order->{ordernumber}); + is( scalar( @$history ), 1, 'GetHistory returns the one order'); + + my $additional_field = $builder->build({source => 'AdditionalField', value => { + tablename => 'aqbasket', + name => 'snakeoil', + authorised_value_category => "", + } + }); + $history = GetHistory( ordernumber => $order->{ordernumber}, additional_fields => [{ id => $additional_field->{id}, value=>'delicious'}]); + is( scalar ( @$history ), 0, 'GetHistory returns no order for an unused additional field'); + my $basket = Koha::Acquisition::Baskets->find({ basketno => $order_basket->{basketno} }); + $basket->set_additional_fields([{ + id => $additional_field->{id}, + value => 'delicious', + }]); + + $history = GetHistory( ordernumber => $order->{ordernumber}, additional_fields => [{ id => $additional_field->{id}, value=>'delicious'}]); + is( scalar( @$history ), 1, 'GetHistory returns the order when additional field is set'); +}; + +subtest 'Tests for get_rounding_sql' => sub { + + plan tests => 2; + + my $value = '3.141592'; + + t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} ); + my $no_rounding_result = C4::Acquisition::get_rounding_sql($value); + t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} ); + my $rounding_result = C4::Acquisition::get_rounding_sql($value); + + ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" ); + ok( $rounding_result =~ /CAST/, "Value ($value) will be rounded" ); + +}; + +subtest 'Test for get_rounded_price' => sub { + + plan tests => 6; + + my $exact_price = 3.14; + my $up_price = 3.145592; + my $down_price = 3.141592; + my $round_up_price = sprintf( '%0.2f', $up_price ); + my $round_down_price = sprintf( '%0.2f', $down_price ); + + t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} ); + my $not_rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); + my $not_rounded_result2 = C4::Acquisition::get_rounded_price($up_price); + my $not_rounded_result3 = C4::Acquisition::get_rounded_price($down_price); + t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} ); + my $rounded_result1 = C4::Acquisition::get_rounded_price($exact_price); + my $rounded_result2 = C4::Acquisition::get_rounded_price($up_price); + my $rounded_result3 = C4::Acquisition::get_rounded_price($down_price); + + is( $not_rounded_result1, $exact_price, "Price ($exact_price) was correctly not rounded ($not_rounded_result1)" ); + is( $not_rounded_result2, $up_price, "Price ($up_price) was correctly not rounded ($not_rounded_result2)" ); + is( $not_rounded_result3, $down_price, "Price ($down_price) was correctly not rounded ($not_rounded_result3)" ); + is( $rounded_result1, $exact_price, "Price ($exact_price) was correctly rounded ($rounded_result1)" ); + is( $rounded_result2, $round_up_price, "Price ($up_price) was correctly rounded ($rounded_result2)" ); + is( $rounded_result3, $round_down_price, "Price ($down_price) was correctly rounded ($rounded_result3)" ); + +}; $schema->storage->txn_rollback(); -- 2.39.5