Bug 14097 : Changing AddReserve prototype call
[koha.git] / t / db_dependent / Log.t
1 #!/usr/bin/perl
2 #
3 # Copyright 2011 MJ Ray and software.coop
4 # This Koha test module is a stub!  
5 # Add more tests here!!!
6
7 use strict;
8 use warnings;
9 use Test::More tests => 7;
10
11 use C4::Context;
12 use Koha::DateUtils;
13
14 use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
15 use Data::Dumper;
16
17 $| = 1;
18
19 BEGIN {
20         use_ok('C4::Log');
21 }
22 my $success;
23
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;
32 };
33 ok($success, "logaction seemed to work");
34
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;
41 };
42 ok($success, "GetLogs returns results for an open search");
43
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;
51 };
52 ok($success, "GetLogs accepts dates in an All-matching search");
53
54 eval {
55     $success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")});
56 } or do {
57     diag($@);
58     $success = 0;
59 };
60 ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search");
61
62 # Make sure we can rollback.
63 my $dbh = C4::Context->dbh;
64 $dbh->{AutoCommit} = 0;
65 $dbh->{RaiseError} = 1;
66
67 # We want numbers to be the same between runs.
68 $dbh->do("DELETE FROM action_logs;");
69
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.");
74
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.");
79
80 $dbh->rollback();