Bug 19919: Unit Tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 16 May 2019 07:49:22 +0000 (08:49 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 15 Jul 2019 10:28:05 +0000 (11:28 +0100)
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>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Koha/Account/Lines.t

index 3856f6e..9b8e4fa 100755 (executable)
@@ -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;