From 40a038fe8c0ef69893f5238d11dc56c12cc06ef2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 12 Oct 2016 11:01:54 +0200 Subject: [PATCH] Bug 17430: Make MarkIssueReturned.t create its own data This patch makes MarkIssueReturned.t use t::lib::TestBuilder to create the data it needs. To test: - On master, have a category with categorycode = C - Run: $ prove t/db_dependent/Circulation/MarkIssueReturned.t => FAIL: primary key problems make the tests fail - Apply the patch - Run: $ prove t/db_dependent/Circulation/MarkIssueReturned.t => SUCCESS: Tests are green! - Sign off :-D --- t/db_dependent/Circulation/MarkIssueReturned.t | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Circulation/MarkIssueReturned.t b/t/db_dependent/Circulation/MarkIssueReturned.t index 4c6f52c..a3428eb 100644 --- a/t/db_dependent/Circulation/MarkIssueReturned.t +++ b/t/db_dependent/Circulation/MarkIssueReturned.t @@ -20,22 +20,24 @@ use Modern::Perl; use Test::More tests => 2; use Test::Warn; +use t::lib::Mocks; +use t::lib::TestBuilder; + use C4::Circulation; use C4::Members; use Koha::Library; -use t::lib::Mocks; +my $schema = Koha::Database->schema; my $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; -t::lib::Mocks::mock_preference('AnonymousPatron', ''); +$schema->storage->txn_begin; -my $branchcode = 'B'; -Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store; +my $builder = t::lib::TestBuilder->new; -my $categorycode = 'C'; -$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); +t::lib::Mocks::mock_preference('AnonymousPatron', ''); + +my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; +my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; my %item_branch_infos = ( homebranch => $branchcode, @@ -53,3 +55,7 @@ t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber); $dbh->{PrintError} = 0; eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) }; unlike ( $@, qr, ); + +$schema->storage->txn_rollback; + +1; -- 2.10.1