Bug 2696: (QA follow-up) Add more test, move to subtest
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 24 Apr 2018 16:43:25 +0000 (16:43 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 24 Apr 2018 17:01:48 +0000 (14:01 -0300)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Accounts.t

index 541564e..ab1fc5f 100644 (file)
@@ -18,7 +18,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 26;
+use Test::More tests => 27;
 use Test::MockModule;
 use Test::Warn;
 
@@ -846,7 +846,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
 
 subtest "Koha::Account::Line::void tests" => sub {
 
-    plan tests => 14;
+    plan tests => 12;
 
     # Create a borrower
     my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
@@ -877,11 +877,6 @@ subtest "Koha::Account::Line::void tests" => sub {
         }
     );
 
-    # Test debit and credit methods fo Koha::Account::Offset
-    my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
-    is( $account_offset->debit->id, $line1->id, "Koha::Account::Offset->debit gets correct accountline" );
-    is( $account_offset->credit->id, $id, "Koha::Account::Offset->credit gets correct accountline" );
-
     my $account_payment = Koha::Account::Lines->find( $id );
 
     is( $account->balance(), 0, "Account balance is 0" );
@@ -907,4 +902,51 @@ subtest "Koha::Account::Line::void tests" => sub {
     is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
 };
 
+subtest "Koha::Account::Offset credit & debit tests" => sub {
+
+    plan tests => 4;
+
+    # Create a borrower
+    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
+    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
+
+    my $borrower = Koha::Patron->new( {
+        cardnumber => 'kyliehall',
+        surname => 'Hall',
+        firstname => 'Kylie',
+    } );
+    $borrower->categorycode( $categorycode );
+    $borrower->branchcode( $branchcode );
+    $borrower->store;
+
+    my $account = Koha::Account->new({ patron_id => $borrower->id });
+
+    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
+    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
+
+    my $id = $account->pay(
+        {
+            lines  => [$line1, $line2],
+            amount => 30,
+        }
+    );
+
+    # Test debit and credit methods for Koha::Account::Offset
+    my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
+    is( $account_offset->debit->id, $line1->id, "Koha::Account::Offset->debit gets correct accountline" );
+    is( $account_offset->credit->id, $id, "Koha::Account::Offset->credit gets correct accountline" );
+
+    $account_offset = Koha::Account::Offset->new(
+        {
+            credit_id => undef,
+            debit_id  => undef,
+            type      => 'Payment',
+            amount    => 0,
+        }
+    )->store();
+
+    is( $account_offset->debit, undef, "Koha::Account::Offset->debit returns undef if no associated debit" );
+    is( $account_offset->credit, undef, "Koha::Account::Offset->credit returns undef if no associated credit" );
+};
+
 1;