Bugzilla – Attachment 43247 Details for
Bug 14778
DBIC should create/own the DB handler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14778: Make 3 tests pass
Bug-14778-Make-3-tests-pass.patch (text/plain), 6.98 KB, created by
Jonathan Druart
on 2015-10-08 10:42:23 UTC
(
hide
)
Description:
Bug 14778: Make 3 tests pass
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-10-08 10:42:23 UTC
Size:
6.98 KB
patch
obsolete
>From 3d99e7089ed3e8b26df7af0a1cea77e32d987c67 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 8 Oct 2015 11:39:19 +0100 >Subject: [PATCH] Bug 14778: Make 3 tests pass > >--- > t/db_dependent/Borrower.t | 14 ++++++-------- > t/db_dependent/Items.t | 40 ++++++++++++++-------------------------- > t/db_dependent/Reports_Guided.t | 12 +++++------- > 3 files changed, 25 insertions(+), 41 deletions(-) > >diff --git a/t/db_dependent/Borrower.t b/t/db_dependent/Borrower.t >index 8290cab..c619754 100755 >--- a/t/db_dependent/Borrower.t >+++ b/t/db_dependent/Borrower.t >@@ -28,13 +28,11 @@ BEGIN { > use_ok('Koha::Borrower'); > } > >-# Start transaction >-my $dbh = C4::Context->dbh; >-$dbh->{AutoCommit} = 0; >-$dbh->{RaiseError} = 1; >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; > >-my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); >-my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); >+my $categorycode = $schema->resultset('Category')->first()->categorycode(); >+my $branchcode = $schema->resultset('Branch')->first()->branchcode(); > > my $object = Koha::Borrower->new(); > >@@ -49,7 +47,7 @@ is( $object->in_storage, 1, "Object is now stored" ); > > my $borrowernumber = $object->borrowernumber; > >-my $borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber ); >+my $borrower = $schema->resultset('Borrower')->find( $borrowernumber ); > is( $borrower->surname(), "Test Surname", "Object found in database" ); > > is( $object->is_changed(), 0, "Object is unchanged" ); >@@ -67,7 +65,7 @@ $object->store(); > is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" ); > > $object->delete(); >-$borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber ); >+$borrower = $schema->resultset('Borrower')->find( $borrowernumber ); > ok( ! $borrower, "Object no longer found in database" ); > is( $object->in_storage, 0, "Object is not in storage" ); > >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index f453aa3..ae9d4df 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -34,7 +34,8 @@ BEGIN { > use_ok('Koha::Items'); > } > >-my $dbh = C4::Context->dbh; >+my $schema = Koha::Database->new->schema; >+ > my $branches = GetBranches; > my ($branch1, $branch2) = keys %$branches; > my $location = 'My Location'; >@@ -43,9 +44,7 @@ subtest 'General Add, Get and Del tests' => sub { > > plan tests => 14; > >- # Start transaction >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin; > > # Create a biblio instance for testing > C4::Context->set_preference('marcflavour', 'MARC21'); >@@ -88,7 +87,7 @@ subtest 'General Add, Get and Del tests' => sub { > is( $getitem->{location}, 'CART', "The location should have been set to CART" ); > is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" ); > >- $dbh->rollback; >+ $schema->storage->txn_rollback; > }; > > subtest 'GetHiddenItemnumbers tests' => sub { >@@ -97,9 +96,7 @@ subtest 'GetHiddenItemnumbers tests' => sub { > > # This sub is controlled by the OpacHiddenItems system preference. > >- # Start transaction >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin; > > # Create a new biblio > C4::Context->set_preference('marcflavour', 'MARC21'); >@@ -175,16 +172,14 @@ subtest 'GetHiddenItemnumbers tests' => sub { > @hidden = GetHiddenItemnumbers( @items ); > ok( scalar @hidden == 0, "Empty items list, no item hidden"); > >- $dbh->rollback; >+ $schema->storage->txn_rollback; > }; > > subtest 'GetItemsInfo tests' => sub { > > plan tests => 4; > >- # Start transaction >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin; > > # Add a biblio > my ($biblionumber, $biblioitemnumber) = get_biblio(); >@@ -212,16 +207,14 @@ subtest 'GetItemsInfo tests' => sub { > is( exists( $results[0]->{ onsite_checkout } ), 1, > 'GetItemsInfo returns a onsite_checkout key' ); > >- $dbh->rollback; >+ $schema->storage->txn_rollback; > }; > > subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { > > plan tests => 4; > >- # Start transaction >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin; > > my $schema = Koha::Database->new()->schema(); > >@@ -260,15 +253,14 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { > $effective_itemtype eq 'BIB_LEVEL', > '$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' ); > >- $dbh->rollback; >+ $schema->storage->txn_rollback; > }; > > subtest 'SearchItems test' => sub { > plan tests => 14; > >- # Start transaction >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin; >+ my $dbh = C4::Context->dbh; > > C4::Context->set_preference('marcflavour', 'MARC21'); > my $cpl_items_before = SearchItemsByField( 'homebranch', 'CPL'); >@@ -424,17 +416,14 @@ subtest 'SearchItems test' => sub { > my $cpl_items_after = SearchItemsByField( 'homebranch', 'CPL'); > is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' ); > >- $dbh->rollback; >+ $schema->storage->txn_rollback; > }; > > subtest 'Koha::Item(s) tests' => sub { > > plan tests => 5; > >- # Start transaction >- my $schema = Koha::Database->new()->schema(); > $schema->storage->txn_begin(); >- $dbh->{RaiseError} = 1; > > # Create a biblio and item for testing > C4::Context->set_preference('marcflavour', 'MARC21'); >@@ -457,8 +446,7 @@ subtest 'Koha::Item(s) tests' => sub { > subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { > plan tests => 7; > >- $dbh->{AutoCommit} = 0; >- $dbh->{RaiseError} = 1; >+ $schema->storage->txn_begin(); > > my ( $biblionumber, $biblioitemnumber ) = get_biblio(); > my $item_infos = [ >diff --git a/t/db_dependent/Reports_Guided.t b/t/db_dependent/Reports_Guided.t >index 04f6fd7..649e33a 100755 >--- a/t/db_dependent/Reports_Guided.t >+++ b/t/db_dependent/Reports_Guided.t >@@ -21,6 +21,7 @@ use Test::More tests => 18; > use Test::Warn; > > use C4::Context; >+use Koha::Database; > > BEGIN { > use_ok('C4::Reports::Guided'); >@@ -30,11 +31,10 @@ can_ok( > qw(save_report delete_report execute_query) > ); > >-#Start transaction >-my $dbh = C4::Context->dbh; >-$dbh->{RaiseError} = 1; >-$dbh->{AutoCommit} = 0; >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; > >+my $dbh = C4::Context->dbh; > $dbh->do(q|DELETE FROM saved_sql|); > $dbh->do(q|DELETE FROM saved_reports|); > >@@ -118,6 +118,4 @@ ok( > is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC', 'SER' ], > "get_report_areas returns the correct array of report areas"); > >-#End transaction >-$dbh->rollback; >- >+$schema->storage->txn_rollback; >-- >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 14778
:
42326
|
42388
|
43247
|
43248
|
43249
|
43250
|
43440
|
43631
|
43632
|
43633
|
43634
|
43635
|
43636
|
43637
|
43638
|
43639
|
43640
|
43641
|
43642
|
43643
|
43644
|
43645
|
43834
|
43835
|
43836
|
43837
|
43838
|
43839
|
43840
|
43841
|
43842
|
43843
|
43844
|
43845
|
43846
|
43847
|
43848
|
43849
|
43850
|
43851
|
43852
|
43853
|
43857
|
43858
|
43859
|
43860
|
43861
|
43862
|
43863
|
43864
|
43865
|
43866
|
43867
|
43868
|
43869
|
43870
|
43871
|
43872
|
43873
|
43874
|
43875
|
43876
|
44003