View | Details | Raw Unified | Return to bug 16829
Collapse All | Expand All

(-)a/t/db_dependent/Log.t (-4 / +66 lines)
Lines 5-17 Link Here
5
# Add more tests here!!!
5
# Add more tests here!!!
6
6
7
use Modern::Perl;
7
use Modern::Perl;
8
use Test::More tests => 8;
8
use Test::More tests => 10;
9
9
10
use C4::Context;
10
use C4::Context;
11
use Koha::DateUtils;
11
use Koha::DateUtils;
12
12
13
use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
13
use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
14
use Data::Dumper;
15
14
16
$| = 1;
15
$| = 1;
17
16
Lines 92-95 subtest "GetLogs should return all logs if dates are not set" => sub { Link Here
92
    is( scalar(@$logs), 1, 'GetLogs should return the logs for today' );
91
    is( scalar(@$logs), 1, 'GetLogs should return the logs for today' );
93
};
92
};
94
93
95
$dbh->rollback();
94
subtest 'logaction(): interface is correctly logged' => sub {
95
96
    plan tests => 4;
97
98
    # No interface passed, using C4::Context->interface
99
    $dbh->do("DELETE FROM action_logs;");
100
    C4::Context->interface( 'commandline' );
101
    logaction( "MEMBERS", "MODIFY", 1, "test operation");
102
    my $logs = GetLogs();
103
    is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly deduced (commandline)');
104
105
    # No interface passed, using C4::Context->interface
106
    $dbh->do("DELETE FROM action_logs;");
107
    C4::Context->interface( 'opac' );
108
    logaction( "MEMBERS", "MODIFY", 1, "test operation");
109
    $logs = GetLogs();
110
    is( @{$logs}[0]->{ interface }, 'opac', 'Interface correctly deduced (opac)');
111
112
    # Explicit interfaces
113
    $dbh->do("DELETE FROM action_logs;");
114
    C4::Context->interface( 'intranet' );
115
    logaction( "MEMBERS", "MODIFY", 1, 'test info', 'intranet');
116
    $logs = GetLogs();
117
    is( @{$logs}[0]->{ interface }, 'intranet', 'Passed interface is respected (intranet)');
118
119
    # Explicit interfaces
120
    $dbh->do("DELETE FROM action_logs;");
121
    C4::Context->interface( 'sip' );
122
    logaction( "MEMBERS", "MODIFY", 1, 'test info', 'sip');
123
    $logs = GetLogs();
124
    is( @{$logs}[0]->{ interface }, 'sip', 'Passed interface is respected (sip)');
125
126
    $dbh->rollback;
127
};
128
129
subtest 'GetLogs() respects interface filters' => sub {
130
131
    plan tests => 5;
132
133
    $dbh->do("DELETE FROM action_logs;");
134
135
    logaction( 'MEMBERS', 'MODIFY', 1, 'opac info',        'opac');
136
    logaction( 'MEMBERS', 'MODIFY', 1, 'sip info',         'sip');
137
    logaction( 'MEMBERS', 'MODIFY', 1, 'intranet info',    'intranet');
138
    logaction( 'MEMBERS', 'MODIFY', 1, 'commandline info', 'commandline');
139
140
    my $logs = scalar @{ GetLogs() };
141
    is( $logs, 4, 'If no filter on interfaces is passed, all logs are returned');
142
143
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['opac']);
144
    is( @{$logs}[0]->{ interface }, 'opac', 'Interface correctly filtered (opac)');
145
146
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['sip']);
147
    is( @{$logs}[0]->{ interface }, 'sip', 'Interface correctly filtered (sip)');
148
149
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['intranet']);
150
    is( @{$logs}[0]->{ interface }, 'intranet', 'Interface correctly filtered (intranet)');
151
152
    $logs = GetLogs(undef,undef,undef,undef,undef,undef,undef,['commandline']);
153
    is( @{$logs}[0]->{ interface }, 'commandline', 'Interface correctly filtered (commandline)');
154
155
    $dbh->rollback;
156
};
157
158
$dbh->rollback;
96
- 

Return to bug 16829