From 1c8efaf3f9b14caf5f6512149d5fcd957bd3e487 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 11 Jul 2013 11:45:06 +0200 Subject: [PATCH] Bug 10481: Unit tests for C4::Members::AddEnrolmentFeeIfNeeded prove t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t .. ok All tests successful. Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.38 cusr 0.01 csys = 0.41 CPU) Result: PASS Signed-off-by: Srdjan Signed-off-by: Kyle M Hall Signed-off-by: Galen Charlton --- .../Members/AddEnrolmentFeeIfNeeded.t | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t diff --git a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t b/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t new file mode 100644 index 0000000000..46d9ec12ce --- /dev/null +++ b/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t @@ -0,0 +1,56 @@ +use Modern::Perl; +use Test::More tests => 3; + +use C4::Context; +use C4::Members; + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +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 => 'CPL', +); + +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" ); + +$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 ) ); + +$dbh->rollback;