Bug 25998: Add Unit Tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 17 Jul 2020 07:01:06 +0000 (08:01 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 22 Jul 2020 08:17:53 +0000 (10:17 +0200)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Koha/Account/Line.t

index 0b35a59..fc4901c 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 12;
+use Test::More tests => 13;
 use Test::Exception;
 use Test::MockModule;
 
@@ -105,6 +105,48 @@ subtest 'item() tests' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest 'library() tests' => sub {
+
+    plan tests => 4;
+
+    $schema->storage->txn_begin;
+
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $patron  = $builder->build( { source => 'Borrower' } );
+
+    my $line = Koha::Account::Line->new(
+        {
+            borrowernumber  => $patron->{borrowernumber},
+            branchcode      => $library->branchcode,
+            debit_type_code => "OVERDUE",
+            status          => "RETURNED",
+            amount          => 10,
+            interface       => 'commandline',
+        }
+    )->store;
+
+    my $account_line_library = $line->library;
+    is( ref($account_line_library),
+        'Koha::Library',
+        'Koha::Account::Line->library should return a Koha::Library' );
+    is(
+        $line->branchcode,
+        $account_line_library->branchcode,
+        'Koha::Account::Line->library should return the correct library'
+    );
+
+    # Test ON DELETE SET NULL
+    $library->delete;
+    my $found = Koha::Account::Lines->find( $line->accountlines_id );
+    ok( $found, "Koha::Account::Line not deleted when the linked library is deleted" );
+
+    is( $found->library, undef,
+'Koha::Account::Line->library should return undef if linked library has been deleted'
+    );
+
+    $schema->storage->txn_rollback;
+};
+
 subtest 'is_credit() and is_debit() tests' => sub {
 
     plan tests => 4;