From d60beb51f4046328dd3f54ca52cfcfe9c2553d2b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 1 Jul 2016 18:53:00 -0300 Subject: [PATCH] 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 --- t/db_dependent/Log.t | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t index 3904cf0..3d878bd 100644 --- a/t/db_dependent/Log.t +++ b/t/db_dependent/Log.t @@ -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; -- 2.9.0