Bug 13967: (QA followup) Make DBIx control transactions on tests
authorTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 4 Jun 2015 18:12:45 +0000 (15:12 -0300)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 4 Jun 2015 18:12:45 +0000 (15:12 -0300)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
t/db_dependent/Acquisition.t
t/db_dependent/Acquisition/CancelReceipt.t
t/db_dependent/Acquisition/GetBasketsInfosByBookseller.t
t/db_dependent/Acquisition/GetOrdersByBiblionumber.t
t/db_dependent/Acquisition/Invoices.t
t/db_dependent/Acquisition/NewOrder.t
t/db_dependent/Acquisition/OrderFromSubscription.t
t/db_dependent/Acquisition/OrderUsers.t
t/db_dependent/Acquisition/TransferOrder.t
t/db_dependent/Acquisition/close_reopen_basket.t

index 561b5af..83486d2 100755 (executable)
@@ -20,6 +20,7 @@ use Modern::Perl;
 use POSIX qw(strftime);
 
 use Test::More tests => 87;
+use Koha::Database;
 
 BEGIN {
     use_ok('C4::Acquisition');
@@ -116,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
@@ -917,4 +921,4 @@ 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;
+$schema->storage->txn_rollback();
index 1946550..e862fcc 100644 (file)
@@ -11,13 +11,15 @@ use C4::Bookseller;
 use C4::Budgets;
 use t::lib::Mocks;
 
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Acquisition::Order;
 use MARC::Record;
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 my $booksellerid1 = C4::Bookseller::AddBookseller(
     {
@@ -148,4 +150,4 @@ is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" );
 my $item2 = C4::Items::GetItem( $itemnumber2 );
 is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" );
 
-$dbh->rollback;
+$schema->storage->txn_rollback();
index 342d431..b742ddf 100644 (file)
@@ -9,11 +9,13 @@ use C4::Biblio qw( AddBiblio );
 use C4::Bookseller qw( AddBookseller );
 use C4::Budgets qw( AddBudget );
 use C4::Context;
-
+use Koha::Database;
 use Koha::Acquisition::Order;
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
+
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 my $supplierid = C4::Bookseller::AddBookseller(
@@ -94,4 +96,4 @@ $baskets = C4::Acquisition::GetBasketsInfosByBookseller( $supplierid, 1 );
 is( scalar(@$baskets), 1, 'Basket is closed, test allbasket parameter');
 
 
-$dbh->rollback
+$schema->storage->txn_rollback();
index adc11b6..3447b27 100644 (file)
@@ -7,14 +7,15 @@ use C4::Acquisition;
 use C4::Biblio;
 use C4::Bookseller;
 use C4::Budgets;
-
+use Koha::Database;
 use Koha::Acquisition::Order;
 
 use MARC::Record;
 
 #Start transaction
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 my $booksellerid = C4::Bookseller::AddBookseller(
@@ -81,6 +82,6 @@ is(scalar(@orders), 1, '1 order on biblionumber 1');
 is(scalar(@orders), 2, '2 orders on biblionumber 2');
 
 #End transaction
-$dbh->rollback;
+$schema->storage->txn_rollback();
 
 done_testing;
index bac86e0..cb54c97 100644 (file)
@@ -7,6 +7,7 @@ use C4::Bookseller qw( AddBookseller );
 
 use Koha::Acquisition::Order;
 use Koha::Acquisition::Bookseller;
+use Koha::Database;
 
 use Test::More tests => 24;
 
@@ -14,8 +15,9 @@ BEGIN {
     use_ok('C4::Acquisition');
 }
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 $dbh->do(q{DELETE FROM aqinvoices});
@@ -193,5 +195,5 @@ my @invoices_linked_to_subscriptions = map{
 is_deeply( \@invoices_linked_to_subscriptions, [], "GetInvoices return linked_to_subscriptions: there is no invoices linked to subscriptions yet" );
 
 END {
-    $dbh and $dbh->rollback;
+    $dbh and $schema->storage->txn_rollback();
 }
index aa9bfed..b491075 100644 (file)
@@ -8,11 +8,13 @@ use C4::Biblio;
 use C4::Bookseller;
 use C4::Budgets;
 use MARC::Record;
+use Koha::Database;
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Acquisition::Order;
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 my $booksellerid = C4::Bookseller::AddBookseller(
@@ -84,3 +86,5 @@ my $ordernumber = $order->{ordernumber};
 $order = Koha::Acquisition::Order->fetch({ ordernumber => $ordernumber });
 is( $order->{quantityreceived}, 0, 'Koha::Acquisition::Order->insert set quantityreceivedto 0 if undef is given' );
 is( $order->{entrydate}, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), 'Koha::Acquisition::Order->insert set entrydate to today' );
+
+$schema->storage->txn_rollback();
\ No newline at end of file
index e7600ca..8a7290d 100644 (file)
@@ -9,10 +9,12 @@ use_ok('C4::Budgets');
 use_ok('C4::Serials');
 
 use Koha::Acquisition::Order;
+use Koha::Database;
 
 # Start transaction
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 my $booksellerid = C4::Bookseller::AddBookseller(
@@ -109,4 +111,4 @@ my @invoices_linked_to_subscriptions = grep { $_->{is_linked_to_subscriptions} }
 is(scalar(@invoices_linked_to_subscriptions), 1, 'GetInvoices() can identify invoices that are linked to a subscription');
 
 # Cleanup
-$dbh->rollback;
+$schema->storage->txn_rollback();
index aa49a89..02bb815 100644 (file)
@@ -5,12 +5,13 @@ use C4::Acquisition;
 use C4::Biblio;
 use C4::Bookseller;
 use C4::Letters;
-
+use Koha::Database;
 use Koha::Acquisition::Order;
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 # Creating some orders
 my $booksellerid = C4::Bookseller::AddBookseller(
@@ -108,3 +109,5 @@ ModReceiveOrder(
 
 $messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
 is( scalar( @$messages ), 1, 'The letter has been sent to message queue on receiving the order');
+
+$schema->storage->txn_rollback();
index d868240..646e770 100644 (file)
@@ -9,13 +9,16 @@ use C4::Biblio;
 use C4::Items;
 use C4::Bookseller;
 use C4::Budgets;
+use Koha::Database;
 use Koha::DateUtils;
 use Koha::Acquisition::Order;
 use MARC::Record;
 
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
+
 my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
 
 my $booksellerid1 = C4::Bookseller::AddBookseller(
     {
@@ -97,4 +100,4 @@ $order = GetOrder( $newordernumber );
 is ( $order->{ordernumber}, $newordernumber, 'Regression test Bug 11549: After a transfer, receive and cancel the receive should be possible.' );
 is ( $order->{basketno}, $basketno2, 'Regression test Bug 11549: The order still exist in the basket where the transfer has been done.');
 
-$dbh->rollback;
+$schema->storage->txn_rollback();
index a5ae64d..ad489e7 100644 (file)
@@ -8,12 +8,14 @@ use C4::Biblio qw( AddBiblio DelBiblio );
 use C4::Bookseller;
 use C4::Budgets;
 use C4::Context;
-
+use Koha::Database;
 use Koha::Acquisition::Order;
 
 # Start transaction
+my $schema = Koha::Database->new()->schema();
+$schema->storage->txn_begin();
+
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 $dbh->do(q{
@@ -80,4 +82,4 @@ C4::Acquisition::ReopenBasket( $basketno );
 is ( scalar( map { $_->{orderstatus} eq 'ordered' ? 1 : () } @orders ), 0, "No order are ordered, the basket is reopen" );
 is ( scalar( map { $_->{orderstatus} eq 'new' ? 1 : () } @orders ), 2, "2 orders are new, the basket is reopen" );
 
-$dbh->rollback;
+$schema->storage->txn_rollback();