Bug 15764: Fix timestamp sent by KOCT
[koha.git] / t / db_dependent / Log.t
blobe5ef4181c5700acd55e113d2a81b562b6ee2d09a
1 #!/usr/bin/perl
3 # Copyright 2011 MJ Ray and software.coop
4 # This Koha test module is a stub!
5 # Add more tests here!!!
7 use strict;
8 use warnings;
9 use Test::More tests => 7;
11 use C4::Context;
12 use Koha::DateUtils;
14 use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
15 use Data::Dumper;
17 $| = 1;
19 BEGIN {
20 use_ok('C4::Log');
22 my $success;
24 eval {
25 # FIXME: are we sure there is an member number 1?
26 # FIXME: can we remove this log entry somehow?
27 logaction("MEMBERS","MODIFY",1,"test operation");
28 $success = 1;
29 } or do {
30 diag($@);
31 $success = 0;
33 ok($success, "logaction seemed to work");
35 eval {
36 # FIXME: US formatted date hardcoded into test for now
37 $success = scalar(@{GetLogs("","","",undef,undef,"","")});
38 } or do {
39 diag($@);
40 $success = 0;
42 ok($success, "GetLogs returns results for an open search");
44 eval {
45 # FIXME: US formatted date hardcoded into test for now
46 my $date = output_pref( { dt => dt_from_string, datenonly => 1, dateformat => 'iso' } );
47 $success = scalar(@{GetLogs( $date, $date, "", undef, undef, "", "") } );
48 } or do {
49 diag($@);
50 $success = 0;
52 ok($success, "GetLogs accepts dates in an All-matching search");
54 eval {
55 $success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")});
56 } or do {
57 diag($@);
58 $success = 0;
60 ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search");
62 # Make sure we can rollback.
63 my $dbh = C4::Context->dbh;
64 $dbh->{AutoCommit} = 0;
65 $dbh->{RaiseError} = 1;
67 # We want numbers to be the same between runs.
68 $dbh->do("DELETE FROM action_logs;");
70 t::lib::Mocks::mock_preference('CronjobLog',0);
71 cronlogaction();
72 my $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{});
73 is($cronJobCount,0,"Cronjob not logged as expected.");
75 t::lib::Mocks::mock_preference('CronjobLog',1);
76 cronlogaction();
77 $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{});
78 is($cronJobCount,1,"Cronjob logged as expected.");
80 $dbh->rollback();