Bug 16609: Catch warning from Koha::Hold in Hold.t
[koha.git] / t / db_dependent / Acquisition.t
index ef611f6..7c80387 100755 (executable)
@@ -1,14 +1,26 @@
 #!/usr/bin/perl
+
+# 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.
 #
-# This Koha test module is a stub!
-# Add more tests here!!!
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use POSIX qw(strftime);
 
-use C4::Bookseller qw( GetBookSellerFromId );
+use POSIX qw(strftime);
 
-use Test::More tests => 90;
+use Test::More tests => 91;
+use Koha::Database;
 
 BEGIN {
     use_ok('C4::Acquisition');
@@ -17,6 +29,7 @@ BEGIN {
     use_ok('C4::Budgets');
     use_ok('C4::Bookseller');
     use_ok('Koha::Acquisition::Order');
+    use_ok('Koha::Acquisition::Bookseller');
 }
 
 # Sub used for testing C4::Acquisition subs returning order(s):
@@ -104,8 +117,11 @@ sub _check_fields_of_orders {
     );
 }
 
+
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
+
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 # Creating some orders
@@ -119,7 +135,7 @@ my $booksellerid = C4::Bookseller::AddBookseller(
     }
 );
 
-my $booksellerinfo = C4::Bookseller::GetBookSellerFromId($booksellerid);
+my $booksellerinfo = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 
 is( $booksellerinfo->{deliverytime},
     5, 'set deliverytime when creating vendor (Bug 10556)' );
@@ -131,10 +147,18 @@ ok(
 );
 ok( $basket = GetBasket($basketno), "GetBasket($basketno) returns $basket" );
 
+my $bpid=AddBudgetPeriod({
+        budget_period_startdate => '2008-01-01'
+        , budget_period_enddate => '2008-12-31'
+        , budget_period_active  => 1
+        , budget_period_description    => "MAPERI"
+});
+
 my $budgetid = C4::Budgets::AddBudget(
     {
         budget_code => "budget_code_test_getordersbybib",
         budget_name => "budget_name_test_getordersbybib",
+        budget_period_id => $bpid,
     }
 );
 my $budget = C4::Budgets::GetBudget($budgetid);
@@ -319,14 +343,12 @@ my @expectedfields = qw(
   quantity
   currency
   listprice
-  totalamount
   datereceived
   invoiceid
   freight
   unitprice
   quantityreceived
   datecancellationprinted
-  supplierreference
   purchaseordernumber
   basketno
   timestamp
@@ -337,7 +359,6 @@ my @expectedfields = qw(
   gstrate
   discount
   budget_id
-  budgetgroup_id
   budgetdate
   sort1
   sort2
@@ -349,6 +370,10 @@ my @expectedfields = qw(
   subscriptionid
   parent_ordernumber
   orderstatus
+  line_item_id
+  suppliers_reference_number
+  suppliers_reference_qualifier
+  suppliers_report
   title
   author
   basketname
@@ -444,7 +469,10 @@ my @base_expectedfields = qw(
   biblioitemnumber
   datereceived
   orderstatus
-  supplierreference
+  line_item_id
+  suppliers_reference_number
+  suppliers_reference_qualifier
+  suppliers_report
   agerestriction
   budget_branchcode
   gstrate
@@ -458,7 +486,6 @@ my @base_expectedfields = qw(
   publicationyear
   collectiontitle
   invoiceid
-  budgetgroup_id
   place
   issn
   quantityreceived
@@ -472,7 +499,6 @@ my @base_expectedfields = qw(
   budget_expend
   rrp
   cn_sort
-  totalamount
   lccn
   sort1
   volume
@@ -515,14 +541,12 @@ ok(
 );
 
 #
-# Test GetCancelledOrders
+# Test GetOrders { cancelled => 1 }
 #
 
 @expectedfields =
   ( @base_expectedfields, ( 'transferred_to_timestamp', 'transferred_to' ) );
-is( GetCancelledOrders(), undef,
-    "GetCancelledOrders with no params returns undef" );
-@get_orders = GetCancelledOrders($basketno);
+@get_orders = GetOrders($basketno, { cancelled => 1 });
 (
     $test_missing_fields,   $test_extra_fields,
     $test_different_fields, $test_nbr_fields
@@ -531,21 +555,21 @@ is( GetCancelledOrders(), undef,
 is(
     $$test_nbr_fields[0],
     scalar @expectedfields,
-    "GetCancelledOrders gets orders with the right number of fields"
+    "GetOrders { cancelled => 1 } gets orders with the right number of fields"
 );
 is( join( " ", @$test_missing_fields ),
-    '', "GetCancelledOrders gets orders with no missing fields" );
+    '', "GetOrders { cancelled => 1 } gets orders with no missing fields" );
 is( join( " ", @$test_extra_fields ),
-    '', "GetCancelledOrders gets orders with no unexpected fields" );
+    '', "GetOrders { cancelled => 1 } gets orders with no unexpected fields" );
 is( join( " ", @$test_different_fields ),
     '',
-    "GetCancelledOrders gets orders with the right content in every fields" );
+    "GetOrders { cancelled => 1 } gets orders with the right content in every fields" );
 ok(
     (
         ( scalar @get_orders == 1 )
           and grep ( $_->{ordernumber} eq $ordernumbers[3], @get_orders )
     ),
-    "GetCancelledOrders only gets cancelled orders"
+    "GetOrders { cancelled => 1 } only gets cancelled orders"
 );
 
 #
@@ -565,7 +589,10 @@ ok(
   creationdate
   datereceived
   orderstatus
-  supplierreference
+  line_item_id
+  suppliers_reference_number
+  suppliers_reference_qualifier
+  suppliers_report
   isbn
   copyrightdate
   gstrate
@@ -580,7 +607,6 @@ ok(
   title
   closedate
   basketname
-  budgetgroup_id
   invoiceid
   author
   parent_ordernumber
@@ -596,7 +622,6 @@ ok(
   sort2_authcat
   rrp
   unitprice
-  totalamount
   sort1
   ordernumber
   datecreated
@@ -821,9 +846,9 @@ is( $neworder->{'budget_id'}, $budgetid, 'Budget on new order is unchanged' );
 is( $neworder->{ordernumber}, $new_ordernumber, 'Split: test ordernumber' );
 is( $neworder->{parent_ordernumber}, $ordernumbers[1], 'Split: test parent_ordernumber' );
 
-my ( $orders ) = GetHistory( ordernumber => $ordernumbers[1] );
+my $orders = GetHistory( ordernumber => $ordernumbers[1] );
 is( scalar( @$orders ), 1, 'GetHistory with a given ordernumber returns 1 order' );
-( $orders ) = GetHistory( ordernumber => $ordernumbers[1], search_children_too => 1 );
+$orders = GetHistory( ordernumber => $ordernumbers[1], search_children_too => 1 );
 is( scalar( @$orders ), 2, 'GetHistory with a given ordernumber and search_children_too set returns 2 orders' );
 
 my $budgetid2 = C4::Budgets::AddBudget(
@@ -913,4 +938,14 @@ ok(($order4->{cancellationreason} eq "foobar"), "order has cancellation reason \
 ok((not defined GetBiblio($order4->{biblionumber})), "biblio does not exist anymore");
 # End of tests for DelOrder
 
-$dbh->rollback;
+# Budget reports
+my $all_count = scalar GetBudgetsReport();
+ok($all_count >= 1, "GetBudgetReport OK");
+
+my $active_count = scalar GetBudgetsReport(1);
+ok($active_count >= 1 , "GetBudgetsReport(1) OK");
+
+is($all_count, scalar GetBudgetsReport(), "GetBudgetReport returns inactive budget period acquisitions.");
+ok($active_count >= scalar GetBudgetsReport(1), "GetBudgetReport doesn't return inactive budget period acquisitions.");
+
+$schema->storage->txn_rollback();