2 # This file is part of Koha.
4 # Copyright 2019 Koha Development Team
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>.
20 use Test::More tests => 3;
25 use Koha::DateUtils qw( dt_from_string );
27 use t::lib::TestBuilder;
30 use_ok('Koha::ActionLogs');
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
36 subtest 'store() tests' => sub {
39 $schema->storage->txn_begin;
41 my $logs_count = Koha::ActionLogs->count;
42 my $log = Koha::ActionLog->new({
43 module => 'CIRCULATION',
45 interface => 'intranet',
47 $log->discard_changes;
49 is( ref($log), 'Koha::ActionLog', 'Log object creation success');
50 is( Koha::ActionLogs->count, $logs_count + 1, 'Exactly one log was saved');
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' );
58 $schema->storage->txn_rollback;
61 subtest 'search() tests' => sub {
64 $schema->storage->txn_begin;
66 my $patron1 = $builder->build_object({
67 class => 'Koha::Patrons',
70 logaction("MEMBERS", "MODIFY", $patron1->borrowernumber, "test");
72 is(Koha::ActionLogs->search({ object => $patron1->borrowernumber })->count, 1, 'search() return right number of action logs');
74 $schema->storage->txn_rollback;