Bug 13517 [QA Followup] - Add unit tests
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 25 Jun 2015 19:17:12 +0000 (15:17 -0400)
committerJesse Weaver <jweaver@bywatersolutions.com>
Wed, 30 Dec 2015 23:42:42 +0000 (16:42 -0700)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
t/db_dependent/Hold.t

index ccd24cd..a91917c 100755 (executable)
@@ -19,8 +19,9 @@ use Modern::Perl;
 
 use C4::Context;
 use Koha::Database;
+use Koha::Borrowers;
 
-use Test::More tests => 8;
+use Test::More tests => 16;
 
 use_ok('Koha::Hold');
 
@@ -30,13 +31,25 @@ $schema->storage->txn_begin();
 my $dbh = C4::Context->dbh;
 $dbh->{RaiseError} = 1;
 
-my $hold = Koha::Hold->new({ found => 'W', waitingdate => '2000-01-01'});
+my $borrower = Koha::Borrowers->search()->next();
+my $hold = Koha::Hold->new(
+    {
+        found          => 'W',
+        waitingdate    => '2000-01-01',
+        borrowernumber => $borrower->borrowernumber(),
+    }
+);
+my $hold_borrower = $hold->borrower();
+ok( $hold_borrower, 'Got hold borrower' );
+is( $hold_borrower->borrowernumber(), $borrower->borrowernumber(), 'Hold borrower matches correct borrower' );
 
 C4::Context->set_preference( 'ReservesMaxPickUpDelay', '' );
 my $dt = $hold->waiting_expires_on();
 is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if ReservesMaxPickUpDelay is not set");
 
 is( $hold->is_waiting, 1, 'The hold is waiting' );
+is( $hold->is_found, 1, 'The hold is found');
+isnt( $hold->is_in_transit,  'The hold is not in transit' );
 
 C4::Context->set_preference( 'ReservesMaxPickUpDelay', '5' );
 $dt = $hold->waiting_expires_on();
@@ -46,11 +59,15 @@ $hold->found('T');
 $dt = $hold->waiting_expires_on();
 is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to 'T' )");
 isnt( $hold->is_waiting, 1, 'The hold is not waiting (T)' );
+is( $hold->is_found, 1, 'The hold is found');
+is( $hold->is_in_transit, 1, 'The hold is in transit' );
 
 $hold->found(q{});
 $dt = $hold->waiting_expires_on();
 is( $dt, undef, "Koha::Hold->waiting_expires_on returns undef if found is not 'W' ( Set to empty string )");
 isnt( $hold->is_waiting, 1, 'The hold is not waiting (W)' );
+is( $hold->is_found, 0, 'The hold is not found' );
+isnt( $hold->is_in_transit, 'The hold is not in transit' );
 
 $schema->storage->txn_rollback();