Bugzilla – Attachment 99043 Details for
Bug 24009
Koha::Account->outstanding_debits should support inline filtering
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24009: Add Unit Tests
Bug-24009-Add-Unit-Tests.patch (text/plain), 9.15 KB, created by
Bouzid Fergani
on 2020-02-14 21:04:38 UTC
(
hide
)
Description:
Bug 24009: Add Unit Tests
Filename:
MIME Type:
Creator:
Bouzid Fergani
Created:
2020-02-14 21:04:38 UTC
Size:
9.15 KB
patch
obsolete
>From a5b768087fa5b81e5db7d7a0c50031954125f561 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 11 Nov 2019 15:45:59 +0000 >Subject: [PATCH] Bug 24009: Add Unit Tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com> >--- > t/db_dependent/Koha/Account.t | 164 ++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 160 insertions(+), 4 deletions(-) > >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index 5437f16..7d3d431 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -24,6 +24,7 @@ use Test::MockModule; > use Test::Exception; > > use Koha::Account; >+use Koha::Account::DebitTypes; > use Koha::Account::Lines; > use Koha::Account::Offsets; > >@@ -53,7 +54,7 @@ subtest 'new' => sub { > > subtest 'outstanding_debits() tests' => sub { > >- plan tests => 22; >+ plan tests => 23; > > $schema->storage->txn_begin; > >@@ -62,9 +63,16 @@ subtest 'outstanding_debits() tests' => sub { > > my @generated_lines; > push @generated_lines, $account->add_debit({ amount => 1, interface => 'commandline', type => 'OVERDUE' }); >- push @generated_lines, $account->add_debit({ amount => 2, interface => 'commandline', type => 'OVERDUE' }); >- push @generated_lines, $account->add_debit({ amount => 3, interface => 'commandline', type => 'OVERDUE' }); >- push @generated_lines, $account->add_debit({ amount => 4, interface => 'commandline', type => 'OVERDUE' }); >+ push @generated_lines, $account->add_debit({ amount => 2, interface => 'commandline', type => 'RESERVE' }); >+ push @generated_lines, $account->add_debit({ amount => 3, interface => 'commandline', type => 'RENT' }); >+ Koha::Account::DebitTypes->find_or_create( >+ { >+ code => 'COPY', >+ description => 'Fee for copie', >+ is_system => 0 >+ } >+ )->store; >+ push @generated_lines, $account->add_debit({ amount => 4, interface => 'commandline', type => 'COPY' }); > > my $lines = $account->outstanding_debits(); > my @lines_arr = $account->outstanding_debits(); >@@ -142,6 +150,154 @@ subtest 'outstanding_debits() tests' => sub { > is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' ); > > $schema->storage->txn_rollback; >+ >+ subtest 'filter_by' => sub { >+ plan tests => 21; >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $account = $patron->account; >+ >+ my $due = 1; >+ my $res = 3; >+ my $rent = 5; >+ my $manual = 7; >+ >+ my @generated_lines; >+ push @generated_lines, $account->add_debit({ amount => $due, interface => 'commandline', type => 'OVERDUE' }); >+ push @generated_lines, $account->add_debit({ amount => $res, interface => 'commandline', type => 'RESERVE' }); >+ push @generated_lines, $account->add_debit({ amount => $rent, interface => 'commandline', type => 'RENT' }); >+ Koha::Account::DebitTypes->find_or_create( >+ { >+ code => 'COPY', >+ description => 'Fee for copie', >+ is_system => 0 >+ } >+ )->store; >+ push @generated_lines, $account->add_debit({ amount => $manual, interface => 'commandline', type => 'COPY' }); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); >+ my ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ my $other_charges = $total - $non_issues_charges; >+ is( >+ $account->balance, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Due + Res + Rent + Manual' >+ ); >+ is( $non_issues_charges, $due, >+ 'If 0|0|0 there should only have been overdue charges' ); >+ is( $other_charges, 15, 'If 0|0|0 there should only have other charges' ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( $non_issues_charges, $due + $manual, >+ 'If 0|0|1 Only Overdue + Manual should be a non issue charge' ); >+ is( >+ $other_charges, >+ $res + $rent, >+ 'If 0|0|1 Res + Rent should be other charges' >+ ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( $non_issues_charges, $due + $rent, >+ 'If 0|1|0 Only Overdue + Rental should be a non issue charge' ); >+ is( >+ $other_charges, >+ $res + $manual, >+ 'If 0|1|0 Rent + Manual should be other charges' >+ ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( >+ $non_issues_charges, >+ $due + $rent + $manual, >+ 'If 0|1|1 Due + Rent + Manual should be non issues charges' >+ ); >+ is( $other_charges, $res, 'If 0|1|1 there should only have other charges' ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( $non_issues_charges, $due + $res, >+ 'If 1|0|0 Only Overdue + Res should be non issues charges' ); >+ is( >+ $other_charges, >+ $rent + $manual, >+ 'If 1|0|0 Rent + Manual should be other charges' >+ ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( >+ $non_issues_charges, >+ $due + $res + $rent, >+ 'If 1|1|0 Overdue + Res + Rent should be non issues charges' >+ ); >+ is( $other_charges, $manual, >+ 'If 1|1|0 Only Manual should be other charges' ); >+ >+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); >+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); >+ ( $total, $non_issues_charges ) = ( $account->balance, $account->outstanding_debits({filter_by => 'blocks_issue'})->total_outstanding ); >+ $other_charges = $total - $non_issues_charges; >+ is( >+ $total, >+ $due + $res + $rent + $manual, >+ 'Total charges should be Res + Rent + Manual' >+ ); >+ is( >+ $non_issues_charges, >+ $due + $res + $rent + $manual, >+ 'If 1|1|1 Res + Rent + Manual should be non issues charges' >+ ); >+ is( $other_charges, 0, 'If 1|1|1 there should not have any other charges' ); >+ >+ $schema->storage->txn_rollback; >+ } > }; > > subtest 'outstanding_credits() tests' => sub { >-- >2.7.4
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 24009
:
95271
|
95272
|
95345
|
95346
|
99041
|
99042
| 99043