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 # Mock the modules we use
31 my $c4_log = Test::MockModule->new('C4::Log');
32 $c4_log->mock('logaction', sub { 1 });
33 my $c4_tpl = Test::MockModule->new('C4::Templates');
34 $c4_tpl->mock('_get_template_file',
35 sub { return ('htdocs', 'theme', 'lang', 'base/'); });
37 use_ok('Koha::Illrequest::Logger');
39 subtest 'Basics' => sub {
43 $schema->storage->txn_begin;
45 my $logger = Koha::Illrequest::Logger->new;
49 ok( defined($logger), 'new() returned something' );
50 ok( $logger->isa('Koha::Illrequest::Logger'),
51 'new() returns the correct object' );
53 # This is an incomplete data hashref, we use it to
54 # test validation of the data before logging
56 modulename => 'modulename',
57 actionname => 'actionname',
63 # Do we only log when the pref is set (currently unset)
64 is($logger->log_something(), '',
65 'logaction() not being called without pref being set');
68 t::lib::Mocks::mock_preference( 'IllLog', 1 );
69 # We should not log without all the required data, we are still
70 # using the incomplete hashref
71 is($logger->log_something(), '',
72 'logaction() being called when data is incomplete');
74 # Fix the data hashref, then test that logging occurs
75 $log_obj->{objectnumber} = 'objectnumber';
76 is($logger->log_something($log_obj), 1,
77 'logaction() being called when pref is set and data is complete');
81 is($logger->log_maybe({}, {}), '',
82 'log_maybe() does not log with incomplete data');
87 $logger->get_log_template({
90 action => 'STATUS_CHANGE'
92 'base/status_change.tt',
93 'get_log_template() fetches correct core template'
96 $schema->storage->txn_rollback;