Bugzilla – Attachment 42994 Details for
Bug 14402
Add --fees option to cleanup_database.pl to purge all 0 balance fees and payments older than the given number of days
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14402: Add unit tests for purge_zero_balance_fees()
Bug-14402-Add-unit-tests-for-purgezerobalancefees.patch (text/plain), 5.31 KB, created by
Jonathan Druart
on 2015-10-01 09:25:03 UTC
(
hide
)
Description:
Bug 14402: Add unit tests for purge_zero_balance_fees()
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-10-01 09:25:03 UTC
Size:
5.31 KB
patch
obsolete
>From af05e5e4d31f83bff2ca470c8399716c80bbf565 Mon Sep 17 00:00:00 2001 >From: Barton Chittenden <barton@bywatersolutions.com> >Date: Sat, 18 Jul 2015 12:58:51 -0700 >Subject: [PATCH] Bug 14402: Add unit tests for purge_zero_balance_fees() > >The function C4::Accounts::purge_zero_balance_fees() should delete rows >in accountlines where amountoutstanding is 0 and accountlines.date is >less than the current date minus '$days', i.e a number of days passed >to the function. Tests were added to prove the following: > >* accountlines.amountoutstanding is 0, and date is set to CURRENT_DATE. > The accountlines row should not be deleted. This is merely a sanity check, > because difference between today's date and the fee date cannot be > greater than $days. >* 'Before', 'On' and 'After' tests for accountlines.amountoutstanding = 0 > * accountlines.amountoutstanding is 0, and date is set to $days - 1 > days ago. The accountlines row should not be deleted. > * accountlines.amountoutstanding is 0, and date is set to $days > days ago. the accountlines row should not be deleted, because > the difference must be *greater* than $days. > * accountlines.amountoutstanding is 0, and date is set to $days + 1 > days ago. The accountlines row *will* be deleted in this case. >* 'Before', 'On' and 'After' tests for accountlines.amountoutstanding > 0. > (3 tests). The accountlines row will never be deleted, because > amountoutstanding is not 0. >* 'Before', 'On' and 'After' tests for accountlines.amountoutstanding < 0. > (3 testes) This tests credits. Again, the accountlines row will never > be deleted, because amountoutstanding is not 0. > >http://bugs.koha-community.org/show_bug.cgi?id=14402 > >Signed-off-by: Nancy Keener <nkeener@washoecounty.us> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Accounts.t | 61 +++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 59 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t >index cefbb3b..61ec951 100644 >--- a/t/db_dependent/Accounts.t >+++ b/t/db_dependent/Accounts.t >@@ -18,7 +18,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 18; > use Test::MockModule; > use Test::Warn; > >@@ -44,7 +44,8 @@ can_ok( 'C4::Accounts', > ReversePayment > recordpayment_selectaccts > makepartialpayment >- WriteOffFee ) >+ WriteOffFee >+ purge_zero_balance_fees ) > ); > > my $builder = t::lib::TestBuilder->new(); >@@ -69,6 +70,62 @@ $context->mock( 'userenv', sub { > }; > }); > >+# Testing purge_zero_balance_fees >+ >+# The 3rd value in the insert is 'days ago' -- >+# 0 => today >+# 1 => yesterday >+# etc. >+ >+$sth = $dbh->prepare( >+ "INSERT INTO accountlines ( >+ borrowernumber, >+ amountoutstanding, >+ date, >+ description >+ ) >+ VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ? )" >+); >+ >+my $days = 5; >+ >+my @test_data = ( >+ { amount => 0 , days_ago => 0 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date today' , delete => 0 } , >+ { amount => 0 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete 0 balance fees with date before threshold day' , delete => 0 } , >+ { amount => 0 , days_ago => $days , description =>'purge_zero_balance_fees should not delete 0 balance fees with date on threshold day' , delete => 0 } , >+ { amount => 0 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should delete 0 balance fees with date after threshold day' , delete => 1 } , >+ { amount => 5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed before threshold day' , delete => 0 } , >+ { amount => 5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with postive amout owed on threshold day' , delete => 0 } , >+ { amount => 5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with postive amout owed after threshold day' , delete => 0 } , >+ { amount => -5 , days_ago => $days - 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed before threshold day' , delete => 0 } , >+ { amount => -5 , days_ago => $days , description =>'purge_zero_balance_fees should not delete fees with negative amout owed on threshold day' , delete => 0 } , >+ { amount => -5 , days_ago => $days + 1 , description =>'purge_zero_balance_fees should not delete fees with negative amout owed after threshold day' , delete => 0 } >+); >+ >+for my $data ( @test_data ) { >+ $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}); >+} >+ >+purge_zero_balance_fees( $days ); >+ >+$sth = $dbh->prepare( >+ "select count(*) = 0 as deleted >+ from accountlines >+ where description = ?" >+ ); >+ >+# >+sub is_delete_correct { >+ my $should_delete = shift; >+ my $description = shift; >+ $sth->execute( $description ); >+ my $test = $sth->fetchrow_hashref(); >+ is( $test->{deleted}, $should_delete, $description ) >+} >+ >+for my $data (@test_data) { >+ is_delete_correct( $data->{delete}, $data->{description}); >+} > > subtest "recordpayment() tests" => sub { > >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14402
:
41043
|
41086
|
41087
|
41088
|
42242
|
42243
|
42244
|
42245
|
42246
|
42477
|
42478
|
42479
|
42480
|
42556
|
42557
|
42815
|
42816
|
42817
|
42818
|
42819
|
42820
|
42993
| 42994 |
42995
|
42996
|
42997
|
44664