Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
|
3 |
use C4::Context; |
4 |
use Koha::Logger; |
5 |
|
6 |
use File::Temp qw/tempfile/; |
7 |
use Test::MockModule; |
8 |
use Test::More tests => 1; |
9 |
|
10 |
subtest 'Test01 -- Simple tests for Koha::Logger' => sub { |
11 |
plan tests => 6; |
12 |
test01(); |
13 |
}; |
14 |
|
15 |
sub test01 { |
16 |
my $mContext = new Test::MockModule('C4::Context'); |
17 |
$mContext->mock( 'config', sub { return; } ); |
18 |
|
19 |
my $logger= Koha::Logger->get; |
20 |
is( exists $logger->{logger}, '', 'No log4perl config'); |
21 |
my $d= $logger->debug('Message 1'); |
22 |
is( $d, undef, 'No return value for debug call'); |
23 |
|
24 |
my $log = mytempfile(); |
25 |
my $conf = mytempfile( <<"HERE" |
26 |
log4perl.logger.intranet = WARN, INTRANET |
27 |
log4perl.appender.INTRANET=Log::Log4perl::Appender::File |
28 |
log4perl.appender.INTRANET.filename=$log |
29 |
log4perl.appender.INTRANET.mode=append |
30 |
log4perl.appender.INTRANET.layout=PatternLayout |
31 |
log4perl.appender.INTRANET.layout.ConversionPattern=[%d] [%p] %m %l %n |
32 |
HERE |
33 |
); |
34 |
$mContext->mock( 'config', sub { return $conf; } ); |
35 |
$logger= Koha::Logger->get({ interface => 'intranet' }); |
36 |
is( exists $logger->{logger}, 1, 'Log4perl config found'); |
37 |
is( $logger->warn('Message 2'), 1, 'Message 2 returned a value' ); |
38 |
is( $logger->catastrophe, undef, 'catastrophe undefined'); |
39 |
system("chmod 400 $log"); |
40 |
is( $logger->warn('Message 3'), undef, 'Message 3 returned undef' ); |
41 |
} |
42 |
|
43 |
sub mytempfile { |
44 |
my ( $fh, $fn ) = tempfile( SUFFIX => '.logger.test', UNLINK => 1 ); |
45 |
print $fh $_[0]//''; |
46 |
close $fh; |
47 |
return $fn; |
48 |
} |