Bug 16912: Koha::Patrons - Move and rewrite tests for AddEnrolmentFeeIfNeeded

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-07-12 08:31:01 +01:00 committed by Kyle M Hall
parent 9c6f634469
commit f9654783e2
2 changed files with 53 additions and 75 deletions

View file

@ -19,7 +19,7 @@
use Modern::Perl; use Modern::Perl;
use Test::More tests => 10; use Test::More tests => 11;
use Test::Warn; use Test::Warn;
use C4::Members; use C4::Members;
@ -251,6 +251,58 @@ subtest "delete" => sub {
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' ); is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
}; };
subtest 'add_enrolment_fee_if_needed' => sub {
plan tests => 4;
my $enrolmentfee_K = 5;
my $enrolmentfee_J = 10;
my $enrolmentfee_YA = 20;
$builder->build( { source => 'Category', value => { categorycode => 'K', enrolmentfee => $enrolmentfee_K } } );
$builder->build( { source => 'Category', value => { categorycode => 'J', enrolmentfee => $enrolmentfee_J } } );
$builder->build( { source => 'Category', value => { categorycode => 'YA', enrolmentfee => $enrolmentfee_YA } } );
my %borrower_data = (
firstname => 'my firstname',
surname => 'my surname',
categorycode => 'K',
branchcode => $library->{branchcode},
);
my $borrowernumber = C4::Members::AddMember(%borrower_data);
$borrower_data{borrowernumber} = $borrowernumber;
my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
$borrower_data{categorycode} = 'J';
C4::Members::ModMember(%borrower_data);
($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
$borrower_data{categorycode} = 'K';
C4::Members::ModMember(%borrower_data);
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
$borrower_data{categorycode} = 'J';
C4::Members::ModMember(%borrower_data);
($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
# Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
my $patron = Koha::Patrons->find($borrowernumber);
$patron->categorycode('YA')->store;
my $fee = $patron->add_enrolment_fee_if_needed;
($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
is( $total,
$enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA,
"Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
);
$patron->delete;
};
$retrieved_patron_1->delete; $retrieved_patron_1->delete;
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );

View file

@ -1,74 +0,0 @@
use Modern::Perl;
use Test::More tests => 4;
use C4::Context;
use C4::Members;
use Koha::Database;
use t::lib::Mocks;
use t::lib::TestBuilder;
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;
my $library = $builder->build({
source => 'Branch',
});
my $enrolmentfee_K = 5;
my $enrolmentfee_J = 10;
my $enrolmentfee_YA = 20;
$dbh->do(q{
UPDATE categories
SET enrolmentfee=?
WHERE categorycode=?
}, {}, $enrolmentfee_K, 'K' );
$dbh->do(q{
UPDATE categories
SET enrolmentfee=?
WHERE categorycode=?
}, {}, $enrolmentfee_J, 'J' );
$dbh->do(q{
UPDATE categories
SET enrolmentfee=?
WHERE categorycode=?
}, {}, $enrolmentfee_YA, 'YA' );
my %borrower_data = (
firstname => 'my firstname',
surname => 'my surname',
categorycode => 'K',
branchcode => $library->{branchcode},
);
my $borrowernumber = C4::Members::AddMember( %borrower_data );
$borrower_data{borrowernumber} = $borrowernumber;
my ( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
$borrower_data{categorycode} = 'J';
C4::Members::ModMember( %borrower_data );
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
is( $total, $enrolmentfee_K , "Kid growing and become a juvenile, but shouldn't pay for the upgrade ");
$borrower_data{categorycode} = 'K';
C4::Members::ModMember( %borrower_data );
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
$borrower_data{categorycode} = 'J';
C4::Members::ModMember( %borrower_data );
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
# Check with calling directly AddEnrolmentFeeIfNeeded
C4::Members::AddEnrolmentFeeIfNeeded( 'YA', $borrowernumber );
( $total ) = C4::Members::GetMemberAccountRecords( $borrowernumber );
is( $total, $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA, "Juvenile growing and become an young adult, he should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA ) );