From 7adcc5624c24851084ad802ed3a6fdea3f91d785 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 2 May 2016 10:06:05 +0200 Subject: [PATCH] Bug 16411: Make Hold.t not depend on two existing branches Content-Type: text/plain; charset=utf-8 If you do not have two branches, this test will fail. Can't call method "branchcode" on an undefined value. This patch adds a borrower and two branches with TestBuilder. Test plan: Run the test. --- t/db_dependent/Hold.t | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index db14f37..204d60e 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -25,6 +25,7 @@ use Koha::Libraries; use Koha::Patrons; use Koha::Item; use Koha::DateUtils; +use t::lib::TestBuilder; use Test::More tests => 31; @@ -33,11 +34,13 @@ use_ok('Koha::Hold'); my $schema = Koha::Database->new()->schema(); $schema->storage->txn_begin(); -my $dbh = C4::Context->dbh; -$dbh->{RaiseError} = 1; - -my @branches = Koha::Libraries->search(); -my $borrower = Koha::Patrons->search()->next(); +# add two branches and a borrower +my $builder = t::lib::TestBuilder->new; +my @branches; +foreach( 1..2 ) { + push @branches, $builder->build({ source => 'Branch' }); +} +my $borrower = $builder->build({ source => 'Borrower' }); my $biblio = MARC::Record->new(); my $title = 'Silence in the library'; @@ -51,8 +54,8 @@ my $item = Koha::Item->new( { biblionumber => $biblionumber, biblioitemnumber => $biblioitemnumber, - holdingbranch => $branches[0]->branchcode(), - homebranch => $branches[0]->branchcode(), + holdingbranch => $branches[0]->{branchcode}, + homebranch => $branches[0]->{branchcode}, } ); $item->store(); @@ -62,8 +65,8 @@ my $hold = Koha::Hold->new( biblionumber => $biblionumber, itemnumber => $item->id(), waitingdate => '2000-01-01', - borrowernumber => $borrower->borrowernumber(), - branchcode => $branches[1]->branchcode(), + borrowernumber => $borrower->{borrowernumber}, + branchcode => $branches[1]->{branchcode}, suspend => 0, } ); @@ -90,7 +93,7 @@ $item = $hold->item(); my $hold_borrower = $hold->borrower(); ok( $hold_borrower, 'Got hold borrower' ); -is( $hold_borrower->borrowernumber(), $borrower->borrowernumber(), 'Hold borrower matches correct borrower' ); +is( $hold_borrower->borrowernumber(), $borrower->{borrowernumber}, 'Hold borrower matches correct borrower' ); t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', '' ); $dt = $hold->waiting_expires_on(); @@ -134,7 +137,7 @@ $hold->found('T'); ok( !$hold->is_at_destination(), "In transit hold cannot be at destination" ); $hold->found('W'); ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the same as the item's holdingbranch is not at destination" ); -$item->holdingbranch( $branches[1]->branchcode() ); +$item->holdingbranch( $branches[1]->{branchcode} ); ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" ); $schema->storage->txn_rollback(); -- 1.7.10.4