Bugzilla – Attachment 12353 Details for
Bug 5339
Parcel closing in acq
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 5339: Unit tests for invoices related subroutines
0002-Bug-5339-Unit-tests-for-invoices-related-subroutines.patch (text/plain), 5.45 KB, created by
Julian Maurice
on 2012-09-19 14:33:48 UTC
(
hide
)
Description:
Bug 5339: Unit tests for invoices related subroutines
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2012-09-19 14:33:48 UTC
Size:
5.45 KB
patch
obsolete
>From 71573e96b83292156041cc3ee7eaf284b5f4335c Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 19 Sep 2012 15:02:49 +0200 >Subject: [PATCH 2/2] Bug 5339: Unit tests for invoices related subroutines > >These tests use DBD::Mock to check if SQL queries are correctly built. >Actually, we only check bound parameters. >--- > C4/Acquisition.pm | 4 +- > t/Acquisition/Invoice.t | 131 +++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 133 insertions(+), 2 deletions(-) > create mode 100755 t/Acquisition/Invoice.t > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 03a55cc..88a968a 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -2204,11 +2204,11 @@ sub GetInvoices { > } > if($args{shipmentdatefrom}) { > push @bind_strs, " aqinvoices.shipementdate >= ? "; >- push @bind_args, $args{shipementdatefrom}; >+ push @bind_args, $args{shipmentdatefrom}; > } > if($args{shipmentdateto}) { > push @bind_strs, " aqinvoices.shipementdate <= ? "; >- push @bind_args, $args{shipementdateto}; >+ push @bind_args, $args{shipmentdateto}; > } > if($args{billingdatefrom}) { > push @bind_strs, " aqinvoices.billingdate >= ? "; >diff --git a/t/Acquisition/Invoice.t b/t/Acquisition/Invoice.t >new file mode 100755 >index 0000000..a887965 >--- /dev/null >+++ b/t/Acquisition/Invoice.t >@@ -0,0 +1,131 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use C4::Context; >+ >+use Test::More tests => 47; >+use Test::MockModule; >+ >+use_ok('C4::Acquisition'); >+ >+my $module = new Test::MockModule('C4::Context'); >+$module->mock('_new_dbh', sub { >+ my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) >+ || die "Cannot create handle: $DBI::errstr\n"; >+ return $dbh; >+}); >+ >+my $dbh = C4::Context->dbh; >+ >+# We need to add a resultset to avoid DBI fail >+# ("DBI bind_columns: invalid number of arguments...") >+my $rs = [ >+ [qw(one two three four)], >+ [1, 2, 3, 4] >+]; >+ >+$dbh->{mock_add_resultset} = $rs; >+my @invoices = C4::Acquisition::GetInvoices( >+ supplierid => "supplierid", >+ invoicenumber => "invoicenumber", >+ suppliername => "suppliername", >+ shipmentdatefrom => "shipmentdatefrom", >+ shipmentdateto => "shipmentdateto", >+ billingdatefrom => "billingdatefrom", >+ billingdateto => "billingdateto", >+ isbneanissn => "isbneanissn", >+ title => "title", >+ author => "author", >+ publisher => "publisher", >+ publicationyear => "publicationyear", >+ branchcode => "branchcode", >+); >+my $history = $dbh->{mock_all_history}; >+ >+is(scalar(@$history), 1); >+my @bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 15); >+is($bound_params[0], 'supplierid'); >+is($bound_params[1], '%invoicenumber%'); >+is($bound_params[2], '%suppliername%'); >+is($bound_params[3], 'shipmentdatefrom'); >+is($bound_params[4], 'shipmentdateto'); >+is($bound_params[5], 'billingdatefrom'); >+is($bound_params[6], 'billingdateto'); >+is($bound_params[7], 'isbneanissn'); >+is($bound_params[8], 'isbneanissn'); >+is($bound_params[9], 'isbneanissn'); >+is($bound_params[10], 'title'); >+is($bound_params[11], 'author'); >+is($bound_params[12], 'publisher'); >+is($bound_params[13], 'publicationyear'); >+is($bound_params[14], 'branchcode'); >+ >+$dbh->{mock_clear_history} = 1; >+$dbh->{mock_add_resultset} = $rs; >+GetInvoice(42); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 1); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 1); >+is($bound_params[0], 42); >+ >+$dbh->{mock_clear_history} = 1; >+$dbh->{mock_add_resultset} = $rs; >+$dbh->{mock_add_resultset} = $rs; >+my $invoice = GetInvoiceDetails(42); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 2); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 1); >+is($bound_params[0], 42); >+@bound_params = @{ $history->[1]->{bound_params} }; >+is(scalar(@bound_params), 1); >+is($bound_params[0], 42); >+ok(exists $invoice->{orders}); >+ >+$dbh->{mock_clear_history} = 1; >+is(AddInvoice(booksellerid => 1), undef); # Fails because of a missing parameter >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 0); >+ >+$dbh->{mock_clear_history} = 1; >+AddInvoice(invoicenumber => 'invoice', booksellerid => 1, unknown => "unknown"); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 1); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 2); >+ok(grep /^1$/, @bound_params); >+ok(grep /^invoice$/, @bound_params); >+ok(not grep /unknown/, @bound_params); >+ >+$dbh->{mock_clear_history} = 1; >+is(ModInvoice(booksellerid => 1), undef); # Fails because of a missing parameter >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 0); >+ >+$dbh->{mock_clear_history} = 1; >+ModInvoice(invoiceid => 3, invoicenumber => 'invoice', unknown => "unknown"); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 1); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 2); >+ok(grep /^3$/, @bound_params); >+ok(grep /^invoice$/, @bound_params); >+ok(not grep /unknown/, @bound_params); >+ >+$dbh->{mock_clear_history} = 1; >+CloseInvoice(42); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 1); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 1); >+is($bound_params[0], 42); >+ >+$dbh->{mock_clear_history} = 1; >+ReopenInvoice(42); >+$history = $dbh->{mock_all_history}; >+is(scalar(@$history), 1); >+@bound_params = @{ $history->[0]->{bound_params} }; >+is(scalar(@bound_params), 1); >+is($bound_params[0], 42); >-- >1.7.10.4 >
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 5339
:
7072
|
7073
|
7447
|
7448
|
7690
|
7691
|
7692
|
7693
|
7862
|
7863
|
7961
|
7962
|
8330
|
8331
|
8354
|
8355
|
8555
|
8556
|
8664
|
8665
|
8858
|
8948
|
8949
|
9382
|
10135
|
10137
|
10460
|
10934
|
11077
|
11535
|
11574
|
12266
|
12267
|
12352
| 12353 |
12369