From a5cc2412a07b06220808a74637f987bcf403c4da Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 28 Jan 2019 20:14:27 +0000 Subject: [PATCH] Bug 21798: (RM follow-up) Fix a few added tests Signed-off-by: Nick Clemens (cherry picked from commit 5d7d741dc4043673202cc41e6e710cce81f57278) Signed-off-by: Martin Renvoize --- t/db_dependent/Circulation.t | 118 ++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 80b19c42fb..b283b7772e 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 122; +use Test::More tests => 124; use Data::Dumper; use DateTime; @@ -2319,13 +2319,13 @@ subtest '_FixAccountForLostAndReturned' => sub { replacementprice => $replacement_amount, itype => $item_type->itemtype }, - $biblionumber + $biblio->biblionumber ); AddIssue( $patron->unblessed, $barcode ); # Simulate item marked as lost - ModItem( { itemlost => 1 }, $biblionumber, $item_id ); + ModItem( { itemlost => 1 }, $biblio->biblionumber, $item_id ); LostItem( $item_id, 1 ); my $lost_fee_lines = Koha::Account::Lines->search( @@ -2842,6 +2842,118 @@ $schema->storage->txn_rollback; C4::Context->clear_syspref_cache(); $cache->clear_from_cache('single_holidays'); +subtest 'AddRenewal and AddIssuingCharge tests' => sub { + + plan tests => 12; + + $schema->storage->txn_begin; + + my $issuing_charges = 15; + my $title = 'A title'; + my $author = 'Author, An'; + my $barcode = 'WHATARETHEODDS'; + + my $circ = Test::MockModule->new('C4::Circulation'); + $circ->mock( + 'GetIssuingCharges', + sub { + return $issuing_charges; + } + ); + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { branchcode => $library->id } + }); + + my $biblio = $builder->build_sample_biblio({ title=> $title, author => $author }); + my ( undef, undef, $item_id ) = AddItem( + { + homebranch => $library->id, + holdingbranch => $library->id, + barcode => $barcode, + replacementprice => 23.00, + itype => $itemtype->id + }, + $biblio->biblionumber + ); + my $item = Koha::Items->find( $item_id ); + + my $items = Test::MockModule->new('C4::Items'); + $items->mock( GetItem => $item->unblessed ); + my $context = Test::MockModule->new('C4::Context'); + $context->mock( userenv => { branch => $library->id } ); + + # Check the item out + AddIssue( $patron->unblessed, $item->barcode ); + + t::lib::Mocks::mock_preference( 'RenewalLog', 0 ); + my $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); + my $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + AddRenewal( $patron->id, $item->id, $library->id ); + my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + is( $new_log_size, $old_log_size, 'renew log not added because of the syspref RenewalLog' ); + + t::lib::Mocks::mock_preference( 'RenewalLog', 1 ); + $date = output_pref( { dt => dt_from_string(), datenonly => 1, dateformat => 'iso' } ); + $old_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + AddRenewal( $patron->id, $item->id, $library->id ); + $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); + + my $lines = Koha::Account::Lines->search({ + borrowernumber => $patron->id, + itemnumber => $item->id + }); + + is( $lines->count, 3 ); + + my $line = $lines->next; + is( $line->accounttype, 'Rent', 'The issuing charge generates an accountline' ); + is( $line->branchcode, $library->id, 'AddIssuingCharge correctly sets branchcode' ); + is( $line->description, 'Rental', 'AddIssuingCharge set a hardcoded description for the accountline' ); + + $line = $lines->next; + is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); + is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); + is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); + + $line = $lines->next; + is( $line->accounttype, 'Rent', 'Fine on renewed item is closed out properly' ); + is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); + is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); + + $schema->storage->txn_rollback; +}; + +subtest 'ProcessOfflinePayment() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $amount = 123; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $result = C4::Circulation::ProcessOfflinePayment({ cardnumber => $patron->cardnumber, amount => $amount, branchcode => $library->id }); + + is( $result, 'Success.', 'The right string is returned' ); + + my $lines = $patron->account->lines; + is( $lines->count, 1, 'line created correctly'); + + my $line = $lines->next; + is( $line->amount+0, $amount * -1, 'amount picked from params' ); + is( $line->branchcode, $library->id, 'branchcode set correctly' ); + + $schema->storage->txn_rollback; +}; + + + sub set_userenv { my ( $library ) = @_; t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); -- 2.39.2