Bugzilla – Attachment 31340 Details for
Bug 12827
NewOrder returns basketno
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12827: NewOrder needs more unit tests
Bug-12827-NewOrder-needs-more-unit-tests.patch (text/plain), 6.24 KB, created by
Jonathan Druart
on 2014-09-03 12:36:19 UTC
(
hide
)
Description:
Bug 12827: NewOrder needs more unit tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-09-03 12:36:19 UTC
Size:
6.24 KB
patch
obsolete
>From 9614f818e3aba9f3b85fbd42b96a71e82a87b821 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 26 Aug 2014 16:43:49 +0200 >Subject: [PATCH] Bug 12827: NewOrder needs more unit tests > >NewOrder should be more tested! > >This patch moves the existing unit tests into a new file and adds some >unit tests. > >Note that there is no DB field aqorders.subscription, so the test in >NewOrder can be removed. > >Test plan: > prove t/db_dependent/Acquisition/NewOrder.t >and > prove t/db_dependent/Acquisition.t >should return green. >--- > C4/Acquisition.pm | 2 +- > t/db_dependent/Acquisition.t | 42 +---------------- > t/db_dependent/Acquisition/NewOrder.t | 86 +++++++++++++++++++++++++++++++++++ > 3 files changed, 88 insertions(+), 42 deletions(-) > create mode 100644 t/db_dependent/Acquisition/NewOrder.t > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 3159a16..93a1855 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -1269,8 +1269,8 @@ sub NewOrder { > croak "Cannot insert order: Mandatory parameter $key is missing" unless $orderinfo->{$key}; > } > >- $orderinfo->{entrydate} ||= output_pref({ dt => dt_from_string, dateformat => 'iso'}); > $orderinfo->{quantityreceived} ||= 0; >+ $orderinfo->{entrydate} ||= output_pref({ dt => dt_from_string, dateformat => 'iso'}); > > # get only the columns of Aqorder > my $schema = Koha::Database->new()->schema; >diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t >index 2a3e8c7..d3e9254 100755 >--- a/t/db_dependent/Acquisition.t >+++ b/t/db_dependent/Acquisition.t >@@ -8,7 +8,7 @@ use POSIX qw(strftime); > > use C4::Bookseller qw( GetBookSellerFromId ); > >-use Test::More tests => 79; >+use Test::More tests => 74; > > BEGIN { > use_ok('C4::Acquisition'); >@@ -144,46 +144,6 @@ my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' ); > my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' ); > my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' ); > >-# >-# Test NewOrder >-# >- >-my ( $mandatoryparams, $return_error, $basketnum ); >- >-# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing >-eval { $ordernumbers[0] = C4::Acquisition::NewOrder() }; >-$return_error = $@; >-ok( >- ( ! defined $ordernumbers[0] ) >- && ( defined $return_error ), >- "NewOrder with no params returns undef and croaks" >-); >- >-$mandatoryparams = { >- basketno => $basketno, >- quantity => 24, >- biblionumber => $biblionumber1, >- budget_id => $budget->{budget_id}, >-}; >-my @mandatoryparams_keys = keys %$mandatoryparams; >-foreach my $mandatoryparams_key (@mandatoryparams_keys) { >- my %test_missing_mandatoryparams = %$mandatoryparams; >- delete $test_missing_mandatoryparams{$mandatoryparams_key}; >- eval { >- $ordernumbers[0] = >- C4::Acquisition::NewOrder( \%test_missing_mandatoryparams ); >- }; >- $return_error = $@; >- my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing"; >- ok( >- ( !( defined $basketnum || defined $ordernumbers[0] ) ) >- && ( index( $return_error, $expected_error ) >= 0 ), >-"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message" >- ); >-} >- >-# FIXME to do : test the other features of NewOrder >- > # Prepare 5 orders, and make distinction beween fields to be tested with eq and with == > # Ex : a price of 50.1 will be stored internally as 5.100000 > >diff --git a/t/db_dependent/Acquisition/NewOrder.t b/t/db_dependent/Acquisition/NewOrder.t >new file mode 100644 >index 0000000..7c7cd81 >--- /dev/null >+++ b/t/db_dependent/Acquisition/NewOrder.t >@@ -0,0 +1,86 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Test::More tests => 7; >+use C4::Acquisition; >+use C4::Biblio; >+use C4::Bookseller; >+use C4::Budgets; >+use MARC::Record; >+use Koha::DateUtils qw( dt_from_string output_pref ); >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my $booksellerid = C4::Bookseller::AddBookseller( >+ { >+ name => "my vendor", >+ address1 => "bookseller's address", >+ phone => "0123456", >+ active => 1 >+ } >+); >+ >+my $basketno = C4::Acquisition::NewBasket( >+ $booksellerid >+); >+ >+my $budgetid = C4::Budgets::AddBudget( >+ { >+ budget_code => "budget_code_test_getordersbybib", >+ budget_name => "budget_name_test_getordersbybib", >+ } >+); >+ >+my $budget = C4::Budgets::GetBudget( $budgetid ); >+ >+my ($biblionumber1, $biblioitemnumber1) = AddBiblio(MARC::Record->new, ''); >+my ($biblionumber2, $biblioitemnumber2) = AddBiblio(MARC::Record->new, ''); >+ >+ >+# returns undef and croaks if basketno, quantity, biblionumber or budget_id is missing >+my $ordernumber = eval { C4::Acquisition::NewOrder() }; >+my $return_error = $@; >+ok( >+ ( ! defined $ordernumber ) >+ && ( defined $return_error ), >+ "NewOrder with no params returns undef and croaks" >+); >+ >+my $mandatoryparams = { >+ basketno => $basketno, >+ quantity => 24, >+ biblionumber => $biblionumber1, >+ budget_id => $budgetid, >+}; >+my @mandatoryparams_keys = keys %$mandatoryparams; >+foreach my $mandatoryparams_key (@mandatoryparams_keys) { >+ my %test_missing_mandatoryparams = %$mandatoryparams; >+ delete $test_missing_mandatoryparams{$mandatoryparams_key}; >+ eval { >+ $ordernumber = >+ C4::Acquisition::NewOrder( \%test_missing_mandatoryparams ); >+ }; >+ $return_error = $@; >+ my $expected_error = "Cannot insert order: Mandatory parameter $mandatoryparams_key is missing"; >+ ok( >+ ( !( defined $ordernumber ) ) >+ && ( index( $return_error, $expected_error ) >= 0 ), >+"NewOrder with no $mandatoryparams_key returns undef and croaks with expected error message" >+ ); >+} >+ >+$ordernumber = C4::Acquisition::NewOrder( >+ { >+ basketno => $basketno, >+ quantity => 24, >+ biblionumber => $biblionumber1, >+ budget_id => $budget->{budget_id}, >+ } >+); >+ >+my $order = C4::Acquisition::GetOrder( $ordernumber ); >+is( $order->{quantityreceived}, 0, 'NewOrder set quantityreceivedto 0 if undef is given' ); >+is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'NewOrder set entrydate to today' ); >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12827
:
31171
|
31172
|
31235
|
31236
|
31339
|
31340
|
31401
|
31402
|
31494
|
31495
|
31519
|
31520
|
31562
|
31563