Bug 16829: Unit tests for logaction's 'interface parameter'

This patch introduces tests for the new 'interface' parameter for the
C4::Log::logaction and C4::Log::GetLogs functions.

In logaction, it falls back to C4::Context->interface if ommited.

To test:
- Run
  $ prove t/db_dependent/Log.t
=> SUCCESS: Tests pass
- Sign off

Sponsored-by: NEKLS

Signed-off-by: Nicole C Engard <nengard@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2016-07-01 18:53:00 -03:00 committed by Kyle M Hall
parent 25cdf47895
commit 3a7aaf1339

View file

@ -5,13 +5,12 @@
# Add more tests here!!!
use Modern::Perl;
use Test::More tests => 8;
use Test::More tests => 10;
use C4::Context;
use Koha::DateUtils;
use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
use Data::Dumper;
$| = 1;
@ -92,4 +91,68 @@ subtest "GetLogs should return all logs if dates are not set" => sub {
is( scalar(@$logs), 1, 'GetLogs should return the logs for today' );
};
$dbh->rollback();
subtest 'logaction(): interface is correctly logged' => sub {
plan tests => 4;
# No interface passed, using C4::Context->interface
$dbh->do("DELETE FROM action_logs;");
C4::Context->interface( 'commandline' );
logaction( "MEMBERS", "MODIFY", 1, "test operation");
my $logs = GetLogs();
is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly deduced (commandline)');
# No interface passed, using C4::Context->interface
$dbh->do("DELETE FROM action_logs;");
C4::Context->interface( 'opac' );
logaction( "MEMBERS", "MODIFY", 1, "test operation");
$logs = GetLogs();
is( @{$logs}[0]->{ interface }, 'opac', 'Interface correctly deduced (opac)');
# Explicit interfaces
$dbh->do("DELETE FROM action_logs;");
C4::Context->interface( 'intranet' );
logaction( "MEMBERS", "MODIFY", 1, 'test info', 'intranet');
$logs = GetLogs();
is( @{$logs}[0]->{ interface }, 'intranet', 'Passed interface is respected (intranet)');
# Explicit interfaces
$dbh->do("DELETE FROM action_logs;");
C4::Context->interface( 'sip' );
logaction( "MEMBERS", "MODIFY", 1, 'test info', 'sip');
$logs = GetLogs();
is( @{$logs}[0]->{ interface }, 'sip', 'Passed interface is respected (sip)');
$dbh->rollback;
};
subtest 'GetLogs() respects interface filters' => sub {
plan tests => 5;
$dbh->do("DELETE FROM action_logs;");
logaction( 'MEMBERS', 'MODIFY', 1, 'opac info', 'opac');
logaction( 'MEMBERS', 'MODIFY', 1, 'sip info', 'sip');
logaction( 'MEMBERS', 'MODIFY', 1, 'intranet info', 'intranet');
logaction( 'MEMBERS', 'MODIFY', 1, 'commandline info', 'commandline');
my $logs = scalar @{ GetLogs() };
is( $logs, 4, 'If no filter on interfaces is passed, all logs are returned');
$logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['opac']);
is( @{$logs}[0]->{ interface }, 'opac', 'Interface correctly filtered (opac)');
$logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['sip']);
is( @{$logs}[0]->{ interface }, 'sip', 'Interface correctly filtered (sip)');
$logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['intranet']);
is( @{$logs}[0]->{ interface }, 'intranet', 'Interface correctly filtered (intranet)');
$logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['commandline']);
is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly filtered (commandline)');
$dbh->rollback;
};
$dbh->rollback;