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

(-)a/t/Log.t (-1 lines)
Lines 10-13 use Test::More tests => 1; Link Here
10
BEGIN {
10
BEGIN {
11
    use_ok('C4::Log');
11
    use_ok('C4::Log');
12
}
12
}
13
(-)a/t/db_dependent/Illrequest/Logger.t (+118 lines)
Line 0 Link Here
1
2
#!/usr/bin/perl
3
4
# This file is part of Koha.
5
#
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.
10
#
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.
15
#
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>.
18
19
use Modern::Perl;
20
21
use Koha::Database;
22
23
use Test::More tests => 2;
24
use Test::MockModule;
25
use Test::MockObject;
26
use t::lib::Mocks;
27
28
my $schema = Koha::Database->new->schema;
29
30
# A mock response from C4::Log::GetLogs()
31
my $logs = [
32
    {
33
        info      => '{"log_origin": "core"}',
34
        action    => 'STATUS_CHANGE',
35
        timestamp => '2018-10-02 11:12:22'
36
    },
37
    {
38
        info      => '{"log_origin": "core"}',
39
        action    => 'STATUS_CHANGE',
40
        timestamp => '2018-10-02 11:12:12'
41
    },
42
    {
43
        info      => '{"log_origin": "core"}',
44
        action    => 'STATUS_CHANGE',
45
        timestamp => '2018-10-02 11:12:32'
46
    }
47
];
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/'); });
55
56
use_ok('Koha::Illrequest::Logger');
57
58
subtest 'Basics' => sub {
59
60
    plan tests => 7;
61
62
    $schema->storage->txn_begin;
63
64
    my $logger = Koha::Illrequest::Logger->new;
65
66
    # new()
67
    #
68
    ok( defined($logger), 'new() returned something' );
69
    ok( $logger->isa('Koha::Illrequest::Logger'),
70
        'new() returns the correct object' );
71
72
    # This is an incomplete data hashref, we use it to
73
    # test validation of the data before logging
74
    my $log_obj = {
75
        modulename   => 'modulename',
76
        actionname   => 'actionname',
77
        infos        => 'infos'
78
    };
79
80
    # log_something()
81
    #
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');
85
86
    # Set the pref
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');
92
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');
97
98
    # log_maybe()
99
    #
100
    is($logger->log_maybe({}, {}), '',
101
        'log_maybe() does not log with incomplete data');
102
103
    # get_log_template()
104
    #
105
    is(
106
        $logger->get_log_template({
107
            request => {},
108
            origin => 'core',
109
            action => 'STATUS_CHANGE'
110
        }),
111
        'base/status_change.tt',
112
        'get_log_template() fetches correct core template'
113
    );
114
115
    $schema->storage->txn_rollback;
116
};
117
118
1;
(-)a/t/db_dependent/Illrequests.t (-4 / +1 lines)
Lines 39-45 use_ok('Koha::Illrequests'); Link Here
39
39
40
subtest 'Basic object tests' => sub {
40
subtest 'Basic object tests' => sub {
41
41
42
    plan tests => 25;
42
    plan tests => 24;
43
43
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
Lines 62-69 subtest 'Basic object tests' => sub { Link Here
62
       "Branchcode getter works.");
62
       "Branchcode getter works.");
63
    is($illrq_obj->status, $illrq->{status},
63
    is($illrq_obj->status, $illrq->{status},
64
       "Status getter works.");
64
       "Status getter works.");
65
    is($illrq_obj->status_alias, $illrq->{status_alias},
66
       "Status_alias getter works.");
67
    is($illrq_obj->placed, $illrq->{placed},
65
    is($illrq_obj->placed, $illrq->{placed},
68
       "Placed getter works.");
66
       "Placed getter works.");
69
    is($illrq_obj->replied, $illrq->{replied},
67
    is($illrq_obj->replied, $illrq->{replied},
70
- 

Return to bug 20750