diff --git a/t/Koha/Script.t b/t/Koha/Script.t index 767a04cce3..a50601da75 100755 --- a/t/Koha/Script.t +++ b/t/Koha/Script.t @@ -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; diff --git a/t/Koha/Script_cron.t b/t/Koha/Script_cron.t index 3e0a4ab5b4..c3e16a00f2 100755 --- a/t/Koha/Script_cron.t +++ b/t/Koha/Script_cron.t @@ -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; diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index 4edaa4d502..4761bd5b7e 100755 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -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;