From b6712ef658fd1f812ccb482c7795a8bf36caa1ef Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Jul 2016 08:31:01 +0100 Subject: [PATCH] Bug 16912: Koha::Patrons - Move and rewrite tests for AddEnrolmentFeeIfNeeded --- t/db_dependent/Koha/Patrons.t | 56 +++++++++++++++++- t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t | 74 ------------------------ 2 files changed, 55 insertions(+), 75 deletions(-) delete mode 100644 t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 0f71655..681db2a 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,9 +19,11 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use Test::Warn; +use C4::Members; + use Koha::Patron; use Koha::Patrons; use Koha::Database; @@ -173,6 +175,58 @@ subtest 'renew_account' => sub { $retrieved_patron->delete; }; +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; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); diff --git a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t b/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t deleted file mode 100644 index cc0a22c..0000000 --- a/t/db_dependent/Members/AddEnrolmentFeeIfNeeded.t +++ /dev/null @@ -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 ) ); -- 2.8.1