Bugzilla – Attachment 57610 Details for
Bug 17653
Remove itemtype-related t/db_dependent/Circulation* warnings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 17653: Remove itemtype-related t/db_dependent/Circulation* warnings
SIGNED-OFF-Bug-17653-Remove-itemtype-related-tdbde.patch (text/plain), 11.23 KB, created by
Josef Moravec
on 2016-11-18 07:00:18 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17653: Remove itemtype-related t/db_dependent/Circulation* warnings
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-11-18 07:00:18 UTC
Size:
11.23 KB
patch
obsolete
>From ae5f4038c54a6720d834aa00fd782eafa37f2f3b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 17 Nov 2016 12:29:14 -0300 >Subject: [PATCH] [SIGNED-OFF] Bug 17653: Remove itemtype-related > t/db_dependent/Circulation* warnings > >This patch makes t/db_dependent/Circulation* create >good sample data for its tests. It does so by creating a random >itemtype. > >To test: >- Run > $ prove t/db_dependent/Circulation* >=> FAIL: lots of warnings about "item-level_itypes set but no itemtype >set for item" >- Apply the patch >- Run: > $ prove t/db_dependent/Circulation* >=> SUCCESS: Tests are green, and no warnings. >- Sign off :-D > >Sponsored-by: ByWater Solutions > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > t/db_dependent/Circulation/CheckIfIssuedToPatron.t | 26 +++++-- > t/db_dependent/Circulation/IsItemIssued.t | 14 ++-- > t/db_dependent/Circulation/transfers.t | 91 +++++++++++++--------- > 3 files changed, 80 insertions(+), 51 deletions(-) > >diff --git a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t >index dc7557c..d2396c9 100644 >--- a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t >+++ b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t >@@ -19,6 +19,7 @@ use Modern::Perl; > > use Test::More tests => 22; > use Test::MockModule; >+use t::lib::TestBuilder; > > use C4::Biblio; > use C4::Items; >@@ -30,6 +31,10 @@ BEGIN { > use_ok('C4::Circulation'); > } > >+my $schema = Koha::Database->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; > > my $dbh = C4::Context->dbh; > $dbh->{AutoCommit} = 0; >@@ -44,23 +49,28 @@ $dbh->do(q|DELETE FROM items|); > $dbh->do(q|DELETE FROM categories|); > > >-my $branchcode = 'B'; >-Koha::Library->new( {branchcode => $branchcode, branchname => 'Branch' } )->store; >+## Create sample data >+# Add a branch >+my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; >+ >+# Add a category >+my $categorycode = $builder->build( { source => 'Category' } )->{categorycode}; > >-my $categorycode = 'C'; >-$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); >+# Add an itemtype >+my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; > >-my %item_branch_infos = ( >- homebranch => $branchcode, >+my %item_info = ( >+ homebranch => $branchcode, > holdingbranch => $branchcode, >+ itype => $itemtype > ); > > my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); > my $barcode1 = '0101'; >-AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1); >+AddItem({ barcode => $barcode1, %item_info }, $biblionumber1); > my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); > my $barcode2 = '0202'; >-AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber2); >+AddItem({ barcode => $barcode2, %item_info }, $biblionumber2); > > my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode); > my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode); >diff --git a/t/db_dependent/Circulation/IsItemIssued.t b/t/db_dependent/Circulation/IsItemIssued.t >index 67c9c74..b63f66f 100644 >--- a/t/db_dependent/Circulation/IsItemIssued.t >+++ b/t/db_dependent/Circulation/IsItemIssued.t >@@ -38,12 +38,14 @@ my $builder = t::lib::TestBuilder->new; > my $library = $builder->build({ source => 'Branch' }); > my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype}; > >-my $module = new Test::MockModule('C4::Context'); >-$module->mock('userenv', sub { >- { >- branch => $library->{branchcode} >- } >-}); >+C4::Context->_new_userenv('DUMMY SESSION'); >+C4::Context->set_userenv( >+ undef, undef, undef, undef, undef, >+ $library->{branchcode}, >+ $library->{branchname} >+); >+ >+ > > my $borrowernumber = AddMember( > firstname => 'my firstname', >diff --git a/t/db_dependent/Circulation/transfers.t b/t/db_dependent/Circulation/transfers.t >index 459f651..1e83f33 100644 >--- a/t/db_dependent/Circulation/transfers.t >+++ b/t/db_dependent/Circulation/transfers.t >@@ -1,5 +1,20 @@ > #!/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. >+# >+# 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 C4::Biblio; > use C4::Context; >@@ -40,37 +55,35 @@ $dbh->do(q|DELETE FROM branches|); > $dbh->do(q|DELETE FROM branch_transfer_limits|); > $dbh->do(q|DELETE FROM branchtransfers|); > >-#Add sample datas >-#Add branches >-my $samplebranch1 = $builder->build({ >- source => 'Branch', >-}); >-my $samplebranch2 = $builder->build({ >- source => 'Branch', >-}); >+## Create sample datas >+# Add branches >+my $branchcode_1 = $builder->build( { source => 'Branch', } )->{branchcode}; >+my $branchcode_2 = $builder->build( { source => 'Branch', } )->{branchcode}; >+# Add itemtype >+my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; > > #Add biblio and items > my $record = MARC::Record->new(); > $record->append_fields( >- MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); >+ MARC::Field->new( '952', '0', '0', a => $branchcode_1 ) ); > my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); > > my @sampleitem1 = C4::Items::AddItem( >- { >- barcode => 1, >+ { barcode => 1, > itemcallnumber => 'callnumber1', >- homebranch => $samplebranch1->{branchcode}, >- holdingbranch => $samplebranch1->{branchcode} >+ homebranch => $branchcode_1, >+ holdingbranch => $branchcode_1, >+ itype => $itemtype > }, > $biblionumber > ); > my $item_id1 = $sampleitem1[2]; > my @sampleitem2 = C4::Items::AddItem( >- { >- barcode => 2, >+ { barcode => 2, > itemcallnumber => 'callnumber2', >- homebranch => $samplebranch1->{branchcode}, >- holdingbranch => $samplebranch1->{branchcode} >+ homebranch => $branchcode_1, >+ holdingbranch => $branchcode_1, >+ itype => $itemtype > }, > $biblionumber > ); >@@ -79,30 +92,30 @@ my $item_id2 = $sampleitem2[2]; > #Add transfers > ModItemTransfer( > $item_id1, >- $samplebranch1->{branchcode}, >- $samplebranch2->{branchcode} >+ $branchcode_1, >+ $branchcode_2 > ); > ModItemTransfer( > $item_id2, >- $samplebranch1->{branchcode}, >- $samplebranch2->{branchcode} >+ $branchcode_1, >+ $branchcode_2 > ); > > #Begin Tests > #Test CreateBranchTransferLimit > is( > CreateBranchTransferLimit( >- $samplebranch2->{branchcode}, >- $samplebranch1->{branchcode}, 'CODE' >+ $branchcode_2, >+ $branchcode_1, 'CODE' > ), > 1, > "A Branch TransferLimit has been added" > ); > is(CreateBranchTransferLimit(),undef, > "Without parameters CreateBranchTransferLimit returns undef"); >-is(CreateBranchTransferLimit($samplebranch2->{branchcode}),undef, >+is(CreateBranchTransferLimit($branchcode_2),undef, > "With only tobranch CreateBranchTransferLimit returns undef"); >-is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef, >+is(CreateBranchTransferLimit(undef,$branchcode_2),undef, > "With only frombranch CreateBranchTransferLimit returns undef"); > #FIXME: Currently, we can add a transferlimit even to nonexistent branches because in the database, > #branch_transfer_limits.toBranch and branch_transfer_limits.fromBranch aren't foreign keys >@@ -112,7 +125,7 @@ is(CreateBranchTransferLimit(undef,$samplebranch2->{branchcode}),undef, > my @transfers = GetTransfers($item_id1); > cmp_deeply( > \@transfers, >- [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $samplebranch1->{branchcode}, $samplebranch2->{branchcode} ], >+ [ re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), $branchcode_1, $branchcode_2 ], > "Transfers of the item1" > ); #NOTE: Only the first transfer is returned > @transfers = GetTransfers; >@@ -123,28 +136,28 @@ is_deeply( \@transfers, [], > "GetTransfers with a wrong item id returns an empty array" ); > > #Test GetTransfersFromTo >-my @transferfrom1to2 = GetTransfersFromTo( $samplebranch1->{branchcode}, >- $samplebranch2->{branchcode} ); >+my @transferfrom1to2 = GetTransfersFromTo( $branchcode_1, >+ $branchcode_2 ); > cmp_deeply( > \@transferfrom1to2, > [ > { > itemnumber => $item_id1, > datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), >- frombranch => $samplebranch1->{branchcode} >+ frombranch => $branchcode_1 > }, > { > itemnumber => $item_id2, > datesent => re('^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'), >- frombranch => $samplebranch1->{branchcode} >+ frombranch => $branchcode_1 > } > ], > "Item1 and Item2 has been transferred from branch1 to branch2" > ); >-my @transferto = GetTransfersFromTo( undef, $samplebranch2->{branchcode} ); >+my @transferto = GetTransfersFromTo( undef, $branchcode_2 ); > is_deeply( \@transferto, [], > "GetTransfersfromTo without frombranch returns an empty array" ); >-my @transferfrom = GetTransfersFromTo( $samplebranch1->{branchcode} ); >+my @transferfrom = GetTransfersFromTo( $branchcode_1 ); > is_deeply( \@transferfrom, [], > "GetTransfersfromTo without tobranch returns an empty array" ); > @transferfrom = GetTransfersFromTo(); >@@ -153,7 +166,7 @@ is_deeply( \@transferfrom, [], > > #Test DeleteBranchTransferLimits > is( >- C4::Circulation::DeleteBranchTransferLimits( $samplebranch1->{branchcode} ), >+ C4::Circulation::DeleteBranchTransferLimits( $branchcode_1 ), > 1, > "A Branch TransferLimit has been deleted" > ); >@@ -167,12 +180,16 @@ is(C4::Circulation::DeleteTransfer(),undef,"Without itemid DeleteTransfer return > is(C4::Circulation::DeleteTransfer(-1),'0E0',"with a wrong itemid DeleteTranfer returns 0E0"); > > #Test TransferSlip >-is( C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 5, $samplebranch2->{branchcode}), >+is( C4::Circulation::TransferSlip($branchcode_1, undef, 5, $branchcode_2), > undef, "No tranferslip if invalid or undef itemnumber or barcode" ); >-is( C4::Circulation::TransferSlip($samplebranch1->{branchcode}, $item_id1, 1, $samplebranch2->{branchcode})->{'code'}, >+is( C4::Circulation::TransferSlip($branchcode_1, $item_id1, 1, $branchcode_2)->{'code'}, > 'TRANSFERSLIP', "Get a transferslip on valid itemnumber and/or barcode" ); > cmp_deeply( >- C4::Circulation::TransferSlip($samplebranch1->{branchcode}, $item_id1, undef, $samplebranch2->{branchcode}), >- C4::Circulation::TransferSlip($samplebranch1->{branchcode}, undef, 1, $samplebranch2->{branchcode}), >+ C4::Circulation::TransferSlip($branchcode_1, $item_id1, undef, $branchcode_2), >+ C4::Circulation::TransferSlip($branchcode_1, undef, 1, $branchcode_2), > "Barcode and itemnumber for same item both generate same TransferSlip" > ); >+ >+$schema->storage->txn_rollback; >+ >+1; >-- >2.1.4
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 17653
:
57605
|
57610
|
57614