|
Line 0
Link Here
|
|
|
1 |
# Copyright 2016 KohaSuomi |
| 2 |
# |
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 6 |
# terms of the GNU General Public License as published by the Free Software |
| 7 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 8 |
# version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License along |
| 15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
use Test::More; |
| 20 |
|
| 21 |
use Log::Log4perl; |
| 22 |
use C4::Context; |
| 23 |
C4::Context->interface('commandline'); #Set the context already prior to loading Koha::Logger (this actually doesn't fix the logger interface definition issue. Just doing it like this to show this doesn't work) |
| 24 |
is(C4::Context->interface(), 'commandline', "Current Koha interface is 'commandline'"); #Show in test output what we are expecting to make test plan more understandable |
| 25 |
|
| 26 |
#Initialize the Log4perl to write to /tmp/log4perl_test.log so we can clean it later |
| 27 |
Log::Log4perl::init( t::Koha::Logger::getLog4perlConfig() ); |
| 28 |
|
| 29 |
use Koha::Logger; |
| 30 |
use t::Koha::Logger; |
| 31 |
|
| 32 |
|
| 33 |
################################################################################################## |
| 34 |
#### Test for Bug 16304 - Koha::Logger, lazy load loggers so environment has time to get set #### |
| 35 |
use t::Koha::Logger_Invoker; #Inside the invoker we already get the Koha's interface from C4::Context->interface. Unfortunately use-definitions are resolved before other code is executed, so the context is not yet properly set. |
| 36 |
use t::Koha::Logger_InvokerLazyLoad; #We set the reference to the Koha::Logger as package-level, but dont load the Log::Log4perl-object yet with uninitialized environment |
| 37 |
|
| 38 |
subtest "Logger_Invoker package-level logger has a bad interface", \&Logger_Invoker_badInterface; |
| 39 |
sub Logger_Invoker_badInterface { |
| 40 |
t::Koha::Logger_Invoker::arbitrarySubroutineWritingToLog(); |
| 41 |
|
| 42 |
my $log = t::Koha::Logger::slurpLog('wantArray'); |
| 43 |
ok($log->[0] =~ /\[opac\./, "Log entry doesn't have 'commandline'-interface, but the default 'opac' instead"); |
| 44 |
} |
| 45 |
t::Koha::Logger::clearLog(); |
| 46 |
|
| 47 |
subtest "Logger_InvokerLazyLoad package-level logger has the correct interface", \&Logger_InvokerLazyLoad_correctInterface; |
| 48 |
sub Logger_InvokerLazyLoad_correctInterface { |
| 49 |
t::Koha::Logger_InvokerLazyLoad::arbitrarySubroutineWritingToLog(); |
| 50 |
|
| 51 |
my $log = t::Koha::Logger::slurpLog('wantArray'); |
| 52 |
ok($log->[0] =~ /\[commandline\./, "Log entry has 'commandline'-interface"); |
| 53 |
} |
| 54 |
t::Koha::Logger::clearLog(); |
| 55 |
|
| 56 |
#### END OF Test for Bug 16304 - Koha::Logger, lazy load loggers so environment has time to get set #### |
| 57 |
######################################################################################################### |
| 58 |
|
| 59 |
|
| 60 |
done_testing(); |