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

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2016-10-12 11:01:54 +02:00 committed by Brendan Gallagher
parent f75afef591
commit d5ca2d0433
1 changed files with 14 additions and 8 deletions

View File

@ -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;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
t::lib::Mocks::mock_preference('AnonymousPatron', '');
my $branchcode = 'B';
Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
my $categorycode = 'C';
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
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<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
$schema->storage->txn_rollback;
1;