From 5c0b7afb1cbcc6038079506eb9713280a5453c24 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Sun, 17 Feb 2019 22:45:07 +0000 Subject: [PATCH] Bug 22363: Update Circulation.t to use Koha::ActionLogs instead of GetLogs Test plan: prove t/db_dependent/Circulation.t --- t/db_dependent/Circulation.t | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 707582d..a170ac4 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -43,6 +43,7 @@ use Koha::Patrons; use Koha::Subscriptions; use Koha::Account::Lines; use Koha::Account::Offsets; +use Koha::ActionLogs; my $schema = Koha::Database->schema; $schema->storage->txn_begin; @@ -466,17 +467,27 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); ); 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"]) } ); + my $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); + my %params_renewal = ( + timestamp => { -like => $date . "%" }, + module => "CIRCULATION", + action => "RENEWAL", + ); + my %params_issue = ( + timestamp => { -like => $date . "%" }, + module => "CIRCULATION", + action => "ISSUE" + ); + my $old_log_size = Koha::ActionLogs->count( \%params_renewal ); AddRenewal( $renewing_borrower->{borrowernumber}, $item_7->itemnumber, $branch ); - my $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } ); + my $new_log_size = Koha::ActionLogs->count( \%params_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"]) } ); + $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } ); + $old_log_size = Koha::ActionLogs->count( \%params_renewal ); AddRenewal( $renewing_borrower->{borrowernumber}, $item_7->itemnumber, $branch ); - $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } ); + $new_log_size = Koha::ActionLogs->count( \%params_renewal ); is ($new_log_size, $old_log_size + 1, 'renew log successfully added'); my $fines = Koha::Account::Lines->search( { borrowernumber => $renewing_borrower->{borrowernumber}, itemnumber => $item_7->itemnumber } ); @@ -486,12 +497,12 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); $fines->delete(); - my $old_issue_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["ISSUE"]) } ); - my $old_renew_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } ); + my $old_issue_log_size = Koha::ActionLogs->count( \%params_issue ); + my $old_renew_log_size = Koha::ActionLogs->count( \%params_renewal ); AddIssue( $renewing_borrower,$item_7->barcode,Koha::DateUtils::output_pref({str=>$datedue6->date_due, dateformat =>'iso'}),0,$date, 0, undef ); - $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["RENEWAL"]) } ); + $new_log_size = Koha::ActionLogs->count( \%params_renewal ); is ($new_log_size, $old_renew_log_size + 1, 'renew log successfully added when renewed via issuing'); - $new_log_size = scalar(@{GetLogs( $date, $date, undef,["CIRCULATION"], ["ISSUE"]) } ); + $new_log_size = Koha::ActionLogs->count( \%params_issue ); is ($new_log_size, $old_issue_log_size, 'renew not logged as issue when renewed via issuing'); $fines = Koha::Account::Lines->search( { borrowernumber => $renewing_borrower->{borrowernumber}, itemnumber => $item_7->itemnumber } ); @@ -2868,19 +2879,23 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { # 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"] ) } ); + my %params_renewal = ( + timestamp => { -like => $date . "%" }, + module => "CIRCULATION", + action => "RENEWAL", + ); + my $old_log_size = Koha::ActionLogs->count( \%params_renewal );; AddRenewal( $patron->id, $item->id, $library->id ); - my $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + my $new_log_size = Koha::ActionLogs->count( \%params_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"] ) } ); + $old_log_size = Koha::ActionLogs->count( \%params_renewal ); AddRenewal( $patron->id, $item->id, $library->id ); - $new_log_size = scalar( @{ GetLogs( $date, $date, undef, ["CIRCULATION"], ["RENEWAL"] ) } ); + $new_log_size = Koha::ActionLogs->count( \%params_renewal ); is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); my $lines = Koha::Account::Lines->search({ -- 2.1.4