Merge branch 'new/bug11269' into 3.14.x
[koha.git] / t / db_dependent / Acquisition / OrderFromSubscription.t
index 91936a8..60b1d3a 100644 (file)
@@ -1,19 +1,35 @@
 use Modern::Perl;
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 use Data::Dumper;
 
-use_ok('C4::Serials');
-use_ok('C4::Budgets');
 use_ok('C4::Acquisition');
+use_ok('C4::Biblio');
+use_ok('C4::Budgets');
+use_ok('C4::Serials');
+
+# Start transaction
+my $dbh = C4::Context->dbh;
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+
 my $supplierlist=eval{GetSuppliersWithLateIssues()};
 ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
 
-my $biblionumber = 1;
+my $booksellerid = C4::Bookseller::AddBookseller(
+    {
+        name => "my vendor",
+        address1 => "bookseller's address",
+        phone => "0123456",
+        active => 1
+    }
+);
+
+my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
 my $budgetid;
 my $bpid = AddBudgetPeriod({
     budget_period_startdate => '01-01-2015',
-    budget_period_enddate   => '31-12-2015',
+    budget_period_enddate   => '12-31-2015',
     budget_description      => "budget desc"
 });
 
@@ -28,28 +44,33 @@ my $budget_id = AddBudget({
 });
 
 my $subscriptionid = NewSubscription(
-    undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
-    undef,      undef,  undef, undef, undef,      undef,         undef,  1,
-    "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
-    "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
+    undef,      "",     undef, undef, $budget_id, $biblionumber,
+    '01-01-2013',undef, undef, undef,  undef,
+    undef,      undef,  undef, undef, undef, undef,
+    1,          "notes",undef, '01-01-2013', undef, undef,
+    undef,       undef,  0,    "intnotes",  0,
+    undef, undef, 0,          undef,         '31-12-2013', 0
 );
 die unless $subscriptionid;
+
+my ($basket, $basketno);
+ok($basketno = NewBasket($booksellerid, 1), "NewBasket(  $booksellerid , 1  ) returns $basketno");
+
 my $cost = 42.00;
 my $subscription = GetSubscription( $subscriptionid );
-my ( $basketno, $ordernumber ) = NewOrder({
+my $ordernumber;
+( $basketno, $ordernumber ) = NewOrder({
     biblionumber => $subscription->{biblionumber},
     entrydate => '01-01-2013',
     quantity => 1,
     currency => 'USD',
     listprice => $cost,
     notes => "This is a note",
-    basketno => 1,
+    basketno => $basketno,
     rrp => $cost,
     ecost => $cost,
     gstrate => 0.0500,
-    orderstatus => 0,
+    orderstatus => 'new',
     subscriptionid => $subscription->{subscriptionid},
     budget_id => $budget_id,
 });
@@ -72,8 +93,5 @@ ok( $order->{ecost} == $cost, "test cost for the last order received");
 $order = GetLastOrderNotReceivedFromSubscriptionid( $subscription->{subscriptionid} );
 is ( $order, undef, "test no not received order for a received order");
 
-# cleaning
-DelSubscription( $subscription->{subscriptionid} );
-DelOrder( $subscription->{biblionumber}, $ordernumber );
-DelBudgetPeriod($bpid);
-DelBudget($budget_id);
+# Cleanup
+$dbh->rollback;