From 739aba61a27ea953b69d44123097a7bb7068cea1 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 16 May 2019 08:49:22 +0100
Subject: [PATCH] Bug 19919: Unit Tests

This patch adds unit tests for the addition of a patron accessor to the
Koha::Account::Line object.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 t/db_dependent/Koha/Account/Lines.t | 31 ++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t
index 3856f6ef14..9b8e4fa724 100755
--- a/t/db_dependent/Koha/Account/Lines.t
+++ b/t/db_dependent/Koha/Account/Lines.t
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 8;
+use Test::More tests => 9;
 use Test::Exception;
 
 use C4::Circulation qw/AddIssue AddReturn/;
@@ -34,6 +34,35 @@ use t::lib::TestBuilder;
 my $schema = Koha::Database->new->schema;
 my $builder = t::lib::TestBuilder->new;
 
+subtest 'patron() tests' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $library = $builder->build( { source => 'Branch' } );
+    my $patron = $builder->build( { source => 'Borrower' } );
+
+    my $line = Koha::Account::Line->new(
+    {
+        borrowernumber => $patron->{borrowernumber},
+        accounttype    => "OVERDUE",
+        status         => "RETURNED",
+        amount         => 10,
+        interface      => 'commandline',
+    })->store;
+
+    my $account_line_patron = $line->patron;
+    is( ref( $account_line_patron ), 'Koha::Patron', 'Koha::Account::Line->patron should return a Koha::Patron' );
+    is( $line->borrowernumber, $account_line_patron->borrowernumber, 'Koha::Account::Line->patron should return the correct borrower' );
+
+    $line->borrowernumber(undef)->store;
+    is( $line->patron, undef, 'Koha::Account::Line->patron should return undef if no patron linked' );
+
+    $schema->storage->txn_rollback;
+};
+
+
 subtest 'item() tests' => sub {
 
     plan tests => 3;
-- 
2.20.1 (Apple Git-117)