Bug 19532: (follow-up) aria-hidden attr on OPAC, and more
[koha.git] / t / db_dependent / Koha / ActionLogs.t
1 #!/usr/bin/perl
2 # This file is part of Koha.
3 #
4 # Copyright 2019 Koha Development Team
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 use Test::More tests => 3;
21
22 use C4::Context;
23 use C4::Log qw( logaction );
24 use Koha::Database;
25 use Koha::DateUtils qw( dt_from_string );
26
27 use t::lib::TestBuilder;
28
29 BEGIN {
30   use_ok('Koha::ActionLogs');
31 }
32
33 my $schema  = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
35
36 subtest 'store() tests' => sub {
37     plan tests => 3;
38
39     $schema->storage->txn_begin;
40
41     my $logs_count = Koha::ActionLogs->count;
42     my $log = Koha::ActionLog->new({
43         module => 'CIRCULATION',
44         action => 'ISSUE',
45         interface => 'intranet',
46     })->store;
47     $log->discard_changes;
48
49     is( ref($log), 'Koha::ActionLog', 'Log object creation success');
50     is( Koha::ActionLogs->count, $logs_count + 1, 'Exactly one log was saved');
51
52     my $yesterday = dt_from_string->subtract( days => 1 );
53     $log->timestamp($yesterday)->store;
54     $log->info("a new info")->store;    # Must be 2 different store calls
55     is( dt_from_string( $log->get_from_storage->timestamp ), $yesterday,
56         'timestamp column should not be updated to current_timestamp' );
57
58     $schema->storage->txn_rollback;
59 };
60
61 subtest 'search() tests' => sub {
62     plan tests => 1;
63
64     $schema->storage->txn_begin;
65
66     my $patron1 = $builder->build_object({
67         class => 'Koha::Patrons',
68     });
69
70     logaction("MEMBERS", "MODIFY", $patron1->borrowernumber, "test");
71
72     is(Koha::ActionLogs->search({ object => $patron1->borrowernumber })->count, 1, 'search() return right number of action logs');
73
74     $schema->storage->txn_rollback;
75 };
76
77 1;