4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Test::More tests => 2;
28 my $schema = Koha::Database->new->schema;
30 # A mock response from C4::Log::GetLogs()
33 info => '{"log_origin": "core"}',
34 action => 'STATUS_CHANGE',
35 timestamp => '2018-10-02 11:12:22'
38 info => '{"log_origin": "core"}',
39 action => 'STATUS_CHANGE',
40 timestamp => '2018-10-02 11:12:12'
43 info => '{"log_origin": "core"}',
44 action => 'STATUS_CHANGE',
45 timestamp => '2018-10-02 11:12:32'
48 # Mock the modules we use
49 my $c4_log = Test::MockModule->new('C4::Log');
50 $c4_log->mock('logaction', sub { 1 });
51 $c4_log->mock('GetLogs', sub { return $logs; });
52 my $c4_tpl = Test::MockModule->new('C4::Templates');
53 $c4_tpl->mock('_get_template_file',
54 sub { return ('htdocs', 'theme', 'lang', 'base/'); });
56 use_ok('Koha::Illrequest::Logger');
58 subtest 'Basics' => sub {
62 $schema->storage->txn_begin;
64 my $logger = Koha::Illrequest::Logger->new;
68 ok( defined($logger), 'new() returned something' );
69 ok( $logger->isa('Koha::Illrequest::Logger'),
70 'new() returns the correct object' );
72 # This is an incomplete data hashref, we use it to
73 # test validation of the data before logging
75 modulename => 'modulename',
76 actionname => 'actionname',
82 # Do we only log when the pref is set (currently unset)
83 is($logger->log_something(), '',
84 'logaction() not being called without pref being set');
87 t::lib::Mocks::mock_preference( 'IllLog', 1 );
88 # We should not log without all the required data, we are still
89 # using the incomplete hashref
90 is($logger->log_something(), '',
91 'logaction() being called when data is incomplete');
93 # Fix the data hashref, then test that logging occurs
94 $log_obj->{objectnumber} = 'objectnumber';
95 is($logger->log_something($log_obj), 1,
96 'logaction() being called when pref is set and data is complete');
100 is($logger->log_maybe({}, {}), '',
101 'log_maybe() does not log with incomplete data');
106 $logger->get_log_template({
109 action => 'STATUS_CHANGE'
111 'base/status_change.tt',
112 'get_log_template() fetches correct core template'
115 $schema->storage->txn_rollback;