Bug 17430: Make MarkIssueReturned.t create its own data
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 12 Oct 2016 09:01:54 +0000 (11:01 +0200)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Mon, 17 Oct 2016 22:55:37 +0000 (22:55 +0000)
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>
t/db_dependent/Circulation/MarkIssueReturned.t

index 4c6f52c..a3428eb 100644 (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;
 
-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<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
+
+$schema->storage->txn_rollback;
+
+1;