Bug 16411: Make Hold.t not depend on two existing branches
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 2 May 2016 08:06:05 +0000 (10:06 +0200)
committerBrendan Gallagher <bredan@bywatersolutions.com>
Thu, 5 May 2016 18:26:56 +0000 (18:26 +0000)
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.

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Brendan Gallagher <bredan@bywatersolutions.com>
t/db_dependent/Hold.t

index db14f37..204d60e 100755 (executable)
@@ -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();