Bug 42714: (QA follow-up) Add tests for cronlogaction and Koha::Script logging
t/db_dependent/Log.t - Add subtest verifying cronlogaction() prefixes loginfo with \$0 (the running script path), appends the info parameter, defaults the action to 'Run', and respects custom action values. t/Koha/Script.t - Assert that \$Koha::Script::_cron is false when the module is loaded without the -cron flag, confirming INIT/END blocks will not log. t/Koha/Script_cron.t - Assert that \$Koha::Script::_cron is true when the module is loaded with the -cron flag, confirming INIT/END blocks will log. Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
ece2d64e76
commit
ad5fe0adff
|
|
@ -18,7 +18,7 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 5;
|
||||
use Test::More tests => 6;
|
||||
use Test::Exception;
|
||||
|
||||
BEGIN { use_ok('Koha::Script') }
|
||||
|
|
@ -53,6 +53,8 @@ is_deeply(
|
|||
my $interface = C4::Context->interface;
|
||||
is( $interface, 'commandline', "Context interface set correctly with no flags" );
|
||||
|
||||
ok( !$Koha::Script::_cron, '_cron flag is false when Koha::Script is loaded without -cron' );
|
||||
|
||||
subtest 'lock_exec() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
|
||||
BEGIN { use_ok( "Koha::Script", '-cron' ) }
|
||||
|
||||
|
|
@ -50,4 +50,6 @@ is_deeply(
|
|||
my $interface = C4::Context->interface;
|
||||
is( $interface, 'cron', "Context interface set correctly with -cron" );
|
||||
|
||||
ok( $Koha::Script::_cron, '_cron flag is true when Koha::Script is loaded with -cron' );
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use Modern::Perl;
|
|||
use Data::Dumper qw( Dumper );
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 9;
|
||||
use Test::More tests => 10;
|
||||
|
||||
use C4::Context;
|
||||
use C4::Log qw( logaction cronlogaction );
|
||||
|
|
@ -259,4 +259,27 @@ subtest 'Test storing original version of an item' => sub {
|
|||
is( $info, "item " . Dumper( $original->unblessed ), 'Original version of item logged successfully' );
|
||||
};
|
||||
|
||||
subtest 'cronlogaction(): loginfo uses $0 and appends info' => sub {
|
||||
plan tests => 5;
|
||||
|
||||
Koha::ActionLogs->search( { module => 'CRONJOBS' } )->delete;
|
||||
t::lib::Mocks::mock_preference( 'CronjobLog', 1 );
|
||||
|
||||
cronlogaction( { info => 'extra_info' } );
|
||||
my $log = Koha::ActionLogs->search( { module => 'CRONJOBS' } )->next;
|
||||
like( $log->info, qr/\Q$0\E/, 'cronlogaction prefixes loginfo with $0 (script path)' );
|
||||
like( $log->info, qr/extra_info$/, 'cronlogaction appends the info parameter after the script path' );
|
||||
is( $log->action, 'Run', 'default action is Run' );
|
||||
|
||||
Koha::ActionLogs->search( { module => 'CRONJOBS' } )->delete;
|
||||
cronlogaction( { action => 'End', info => 'COMPLETED' } );
|
||||
$log = Koha::ActionLogs->search( { module => 'CRONJOBS' } )->next;
|
||||
is( $log->action, 'End', 'custom action is respected' );
|
||||
|
||||
Koha::ActionLogs->search( { module => 'CRONJOBS' } )->delete;
|
||||
cronlogaction();
|
||||
$log = Koha::ActionLogs->search( { module => 'CRONJOBS' } )->next;
|
||||
is( $log->info, $0, 'loginfo is exactly $0 when no info param is given' );
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue