Bugzilla – Attachment 47801 Details for
Bug 14097
Add unit tests to C4::UsageStats
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14097: Rollback issue and warning corrected
Bug-14097-Rollback-issue-and-warning-corrected.patch (text/plain), 10.81 KB, created by
Jonathan Druart
on 2016-02-09 12:16:41 UTC
(
hide
)
Description:
Bug 14097: Rollback issue and warning corrected
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-02-09 12:16:41 UTC
Size:
10.81 KB
patch
obsolete
>From 6f3c0860260d24ef689d14a4ddcc6daf6b621e14 Mon Sep 17 00:00:00 2001 >From: Julian FIOL <julian.fiol@biblibre.com> >Date: Tue, 12 May 2015 14:28:56 +0200 >Subject: [PATCH] Bug 14097: Rollback issue and warning corrected > >The rollback issue came from '_count' testing. >It used a 'DROP TABLE' and 'CREATE TABLE' which implicitly do autocommit. >That's why the final rollback could not be. > >This patch no longer uses t::lib::TestBuilder either because it was the cause >of the warning on Comment #1 : >"DBIx::Class::Storage::txn_rollback(): A txn_rollback >in nested transaction is ineffective! (depth 1) at >t/lib/TestBuilder.pm line 308" > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Now data is preserved, no errors. > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/UsageStats.t | 127 +++++++++++++++++++------------------------- > 1 file changed, 56 insertions(+), 71 deletions(-) > >diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t >index 309651c..b98f05b 100644 >--- a/t/db_dependent/UsageStats.t >+++ b/t/db_dependent/UsageStats.t >@@ -15,7 +15,7 @@ > # with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 552; >+use Test::More tests => 551; > use t::lib::Mocks qw(mock_preference); > use POSIX qw(strftime); > >@@ -27,7 +27,6 @@ BEGIN { > use_ok('C4::Reserves'); > use_ok('MARC::Record'); > use_ok('Koha::Acquisition::Order'); >- use_ok('t::lib::TestBuilder'); > } > > can_ok( >@@ -112,7 +111,7 @@ is( $report->{library}->{type}, 'TYPE', "UsageStatsLibraryType is > is( $report->{library}->{country}, 'COUNTRY', "UsageStatsCountry is good" ); > > #Test report->volumetry --------------- >-#without objects >+#with original values > $report = C4::UsageStats->BuildReport(); > > isa_ok( $report, 'HASH', '$report is a HASH' ); >@@ -127,22 +126,22 @@ is( $report->{volumetry}->{borrowers}, 0, "There is no borrowers" ); > is( $report->{volumetry}->{aqorders}, 0, "There is no aqorders" ); > is( $report->{volumetry}->{subscription}, 0, "There is no subscription" ); > >+#after adding objects > construct_objects_needed(); > >-#with objects > $report = C4::UsageStats->BuildReport(); > > isa_ok( $report, 'HASH', '$report is a HASH' ); > isa_ok( $report->{volumetry}, 'HASH', '$report->{volumetry} is a HASH' ); > is( scalar( keys( $report->{volumetry} ) ), 8, "There are 8 fields in $report->{volumetry}" ); >-is( $report->{volumetry}->{biblio}, 4, "There are 4 biblio" ); >+is( $report->{volumetry}->{biblio}, 3, "There are 3 biblio" ); > is( $report->{volumetry}->{items}, 3, "There are 3 items" ); > is( $report->{volumetry}->{auth_header}, 2, "There are 2 auth_header" ); >-is( $report->{volumetry}->{old_issues}, 1, "There is 1 old_issues" ); >-is( $report->{volumetry}->{old_reserves}, 1, "There is 1 old_reserves" ); >+is( $report->{volumetry}->{old_issues}, 1, "There is 1 old_issues" ); >+is( $report->{volumetry}->{old_reserves}, 1, "There is 1 old_reserves" ); > is( $report->{volumetry}->{borrowers}, 3, "There are 3 borrowers" ); >-is( $report->{volumetry}->{aqorders}, 1, "There is 1 aqorders" ); >-is( $report->{volumetry}->{subscription}, 1, "There is 1 subscription" ); >+is( $report->{volumetry}->{aqorders}, 1, "There is 1 aqorders" ); >+is( $report->{volumetry}->{subscription}, 1, "There is 1 subscription" ); > > #Test report->systempreferences ------- > #mock to 0 >@@ -166,20 +165,14 @@ verif_systempreferences_values( $report, 1 ); > # ---------- Testing ReportToCommunity ---------- > > # ---------- Testing _count --------------------- >- >-$dbh->do('DROP TABLE IF EXISTS _exmpl_tbl'); >-$dbh->do('CREATE TABLE _exmpl_tbl (id INT, val VARCHAR(10))'); >-$dbh->do( 'INSERT INTO _exmpl_tbl VALUES(1, ?)', undef, 'Hello' ); >-$dbh->do( 'INSERT INTO _exmpl_tbl VALUES(2, ?)', undef, 'World' ); >- > my $query = ' > SELECT count(*) >- FROM _exmpl_tbl >+ FROM borrowers > '; > my $count = $dbh->selectrow_array($query); > >-my $nb_fields = C4::UsageStats::_count('_exmpl_tbl'); >-is( $nb_fields, $count, "_exmpl_tbl has 2 fields" ); >+my $nb_fields = C4::UsageStats::_count('borrowers'); >+is( $nb_fields, $count, "_count return the good number of fields" ); > > ################################################# > # Subs >@@ -204,28 +197,23 @@ sub construct_objects_needed { > my $firstname1 = 'firstname 1'; > my $firstname2 = 'firstname 2'; > my $firstname3 = 'firstname 3'; >- my $cardnumber1 = '00001'; >- my $cardnumber2 = '00002'; >- my $cardnumber3 = '00003'; >+ my $cardnumber1 = 'test_card1'; >+ my $cardnumber2 = 'test_card2'; >+ my $cardnumber3 = 'test_card3'; > my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); > my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); > > my $query = ' >- INSERT INTO borrowers >+ INSERT INTO borrowers > (surname, firstname, cardnumber, branchcode, categorycode) > VALUES (?,?,?,?,?)'; > my $insert_sth = $dbh->prepare($query); > $insert_sth->execute( $surname1, $firstname1, $cardnumber1, $branchcode, $categorycode ); >+ my $borrowernumber1 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); > $insert_sth->execute( $surname2, $firstname2, $cardnumber2, $branchcode, $categorycode ); >+ my $borrowernumber2 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); > $insert_sth->execute( $surname3, $firstname3, $cardnumber3, $branchcode, $categorycode ); >- >- $query = ' >- SELECT borrowernumber >- FROM borrowers >- WHERE surname = ?'; >- my $borrowernumber1 = $dbh->selectrow_array( $query, {}, $surname1 ); >- my $borrowernumber2 = $dbh->selectrow_array( $query, {}, $surname2 ); >- my $borrowernumber3 = $dbh->selectrow_array( $query, {}, $surname3 ); >+ my $borrowernumber3 = $dbh->last_insert_id( undef, undef, 'borrowers', undef ); > > # ---------- 3 biblios ----------------------- > my $title1 = 'Title 1'; >@@ -253,17 +241,12 @@ sub construct_objects_needed { > (biblionumber, itemtype, marcxml) > VALUES (?,?,?)'; > $insert_sth = $dbh->prepare($query); >- $insert_sth->execute( $biblionumber1, 'Book', '' ); >+ $insert_sth->execute( $biblionumber1, 'Book', '' ); >+ my $biblioitemnumber1 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); > $insert_sth->execute( $biblionumber2, 'Music', '' ); >- $insert_sth->execute( $biblionumber3, 'Book', '' ); >- >- $query = ' >- SELECT biblioitemnumber >- FROM biblioitems >- WHERE biblionumber = ?'; >- my $biblioitemnumber1 = $dbh->selectrow_array( $query, {}, $biblionumber1 ); >- my $biblioitemnumber2 = $dbh->selectrow_array( $query, {}, $biblionumber2 ); >- my $biblioitemnumber3 = $dbh->selectrow_array( $query, {}, $biblionumber3 ); >+ my $biblioitemnumber2 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); >+ $insert_sth->execute( $biblionumber3, 'Book', '' ); >+ my $biblioitemnumber3 = $dbh->last_insert_id( undef, undef, 'biblioitems', undef ); > > # ---------- 3 items ------------------------- > my $barcode1 = '111111'; >@@ -276,16 +259,11 @@ sub construct_objects_needed { > VALUES (?,?,?,?)'; > $insert_sth = $dbh->prepare($query); > $insert_sth->execute( $biblionumber1, $biblioitemnumber1, $barcode1, 'Book' ); >+ my $item_number1 = $dbh->last_insert_id( undef, undef, 'items', undef ); > $insert_sth->execute( $biblionumber2, $biblioitemnumber2, $barcode2, 'Music' ); >+ my $item_number2 = $dbh->last_insert_id( undef, undef, 'items', undef ); > $insert_sth->execute( $biblionumber3, $biblioitemnumber3, $barcode3, 'Book' ); >- >- $query = ' >- SELECT itemnumber >- FROM items >- WHERE barcode = ?'; >- my $item_number1 = $dbh->selectrow_array( $query, {}, $barcode1 ); >- my $item_number2 = $dbh->selectrow_array( $query, {}, $barcode2 ); >- my $item_number3 = $dbh->selectrow_array( $query, {}, $barcode3 ); >+ my $item_number3 = $dbh->last_insert_id( undef, undef, 'items', undef ); > > # ---------- Add 2 auth_header > $query = ' >@@ -294,14 +272,9 @@ sub construct_objects_needed { > VALUES (?)'; > $insert_sth = $dbh->prepare($query); > $insert_sth->execute('authtypecode1'); >+ my $authid1 = $dbh->last_insert_id( undef, undef, 'auth_header', undef ); > $insert_sth->execute('authtypecode2'); >- >- $query = ' >- SELECT authid >- FROM auth_header >- WHERE authtypecode = ?'; >- my $authid1 = $dbh->selectrow_array( $query, {}, 'authtypecode1' ); >- my $authid2 = $dbh->selectrow_array( $query, {}, 'authtypecode2' ); >+ my $authid2 = $dbh->last_insert_id( undef, undef, 'auth_header', undef ); > > # ---------- Add 1 old_issues > $query = ' >@@ -310,12 +283,7 @@ sub construct_objects_needed { > VALUES (?,?,?)'; > $insert_sth = $dbh->prepare($query); > $insert_sth->execute( $borrowernumber1, $branchcode, $item_number1 ); >- >- $query = ' >- SELECT issue_id >- FROM old_issues >- WHERE borrowernumber = ?'; >- my $issue_id1 = $dbh->selectrow_array( $query, {}, $borrowernumber1 ); >+ my $issue_id1 = $dbh->last_insert_id( undef, undef, 'old_issues', undef ); > > # ---------- Add 1 old_reserves > AddReserve( $branchcode, $borrowernumber1, $biblionumber1, 'a', '', 1, undef, undef, '', 'Title', undef, undef ); >@@ -323,16 +291,33 @@ sub construct_objects_needed { > my $reserve_id1 = $reserves1->[0]->{reserve_id}; > my $reserve1 = CancelReserve( { reserve_id => $reserve_id1 } ); > >- # ---------- Add 1 biblio, 1 subscription and 1 aqorder >- my $builder = t::lib::TestBuilder->new(); >- $builder->clear( { source => 'Aqorder' } ); >- my $order1 = $builder->build( >- { source => 'Aqorder', >- value => { datecancellationprinted => undef, }, >- only_fk => 1, >- } >- ); >- my $newordernumber = Koha::Acquisition::Order->new($order1)->insert->{ordernumber}; >+ # ---------- Add 1 aqbudgets >+ $query = ' >+ INSERT INTO aqbudgets >+ (budget_amount) >+ VALUES (?)'; >+ $insert_sth = $dbh->prepare($query); >+ $insert_sth->execute("20.0"); >+ my $aqbudgets1 = $dbh->last_insert_id( undef, undef, 'aqbudgets', undef ); >+ >+ # ---------- Add 1 aqorders >+ $query = ' >+ INSERT INTO aqorders >+ (budget_id, basketno, biblionumber, invoiceid, subscriptionid) >+ VALUES (?,?,?,?,?)'; >+ $insert_sth = $dbh->prepare($query); >+ $insert_sth->execute( $aqbudgets1, undef, undef, undef, undef ); >+ my $aqorders1 = $dbh->last_insert_id( undef, undef, 'aqorders', undef ); >+ >+ # --------- Add 1 subscription >+ $query = ' >+ INSERT INTO subscription >+ (biblionumber) >+ VALUES (?)'; >+ $insert_sth = $dbh->prepare($query); >+ $insert_sth->execute($biblionumber1); >+ my $subscription1 = $dbh->last_insert_id( undef, undef, 'subscription', undef ); >+ > } > > #Change systempreferences values to $set_value >-- >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 14097
:
38719
|
38800
|
38814
|
38946
|
38947
|
38948
|
39080
|
39085
|
39435
|
41837
|
41843
|
41844
|
46200
|
46201
|
46202
|
46203
|
46204
|
46205
|
46206
|
46207
|
46208
|
46209
|
46210
|
46211
|
46212
|
46213
|
46214
|
46215
|
47717
|
47719
|
47720
|
47721
|
47722
|
47723
|
47724
|
47725
|
47726
|
47727
|
47798
|
47799
|
47800
| 47801 |
47802
|
47803
|
47804
|
47805