Bug 21065: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 14 Dec 2018 15:47:11 +0000 (12:47 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 20 Dec 2018 09:29:02 +0000 (09:29 +0000)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 09ef91653bc8e0349d4e8613482251d7e3c165b5)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Koha/Account/Lines.t

index eb8dfdd..2e8f7f2 100755 (executable)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 4;
+use Test::More tests => 5;
 use Test::Exception;
 
 use Koha::Account;
@@ -268,3 +268,30 @@ subtest 'apply() tests' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'Keep account info when a patron is deleted' => sub {
+
+    plan tests => 2;
+
+    $schema->storage->txn_begin;
+
+    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $item = $builder->build_object({ class => 'Koha::Items' });
+    my $line = Koha::Account::Line->new(
+    {
+        borrowernumber => $patron->borrowernumber,
+        itemnumber     => $item->itemnumber,
+        accounttype    => "F",
+        amount         => 10,
+    })->store;
+
+    $item->delete;
+    $line = $line->get_from_storage;
+    is( $line->itemnumber, undef, "The account line should not be deleted when the related item is delete");
+
+    $patron->delete;
+    $line = $line->get_from_storage;
+    is( $line->borrowernumber, undef, "The account line should not be deleted when the related patron is delete");
+
+    $schema->storage->txn_rollback;
+};