3 # Copyright 2011 MJ Ray and software.coop
4 # This Koha test module is a stub!
5 # Add more tests here!!!
8 use Test::More tests => 8;
13 use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
24 # FIXME: are we sure there is an member number 1?
25 # FIXME: can we remove this log entry somehow?
26 logaction("MEMBERS","MODIFY",1,"test operation");
32 ok($success, "logaction seemed to work");
35 # FIXME: US formatted date hardcoded into test for now
36 $success = scalar(@{GetLogs("","","",undef,undef,"","")});
41 ok($success, "GetLogs returns results for an open search");
44 # FIXME: US formatted date hardcoded into test for now
45 my $date = output_pref( { dt => dt_from_string, datenonly => 1, dateformat => 'iso' } );
46 $success = scalar(@{GetLogs( $date, $date, "", undef, undef, "", "") } );
51 ok($success, "GetLogs accepts dates in an All-matching search");
54 $success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")});
59 ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search");
61 # Make sure we can rollback.
62 my $dbh = C4::Context->dbh;
63 $dbh->{AutoCommit} = 0;
64 $dbh->{RaiseError} = 1;
66 # We want numbers to be the same between runs.
67 $dbh->do("DELETE FROM action_logs;");
69 t::lib::Mocks::mock_preference('CronjobLog',0);
71 my $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{});
72 is($cronJobCount,0,"Cronjob not logged as expected.");
74 t::lib::Mocks::mock_preference('CronjobLog',1);
76 $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{});
77 is($cronJobCount,1,"Cronjob logged as expected.");
79 subtest "GetLogs should return all logs if dates are not set" => sub {
81 my $today = dt_from_string->add(minutes => -1);
82 my $yesterday = dt_from_string->add( days => -1 );
84 INSERT INTO action_logs (timestamp, user, module, action, object, info)
86 (?, 42, 'CATALOGUING', 'MODIFY', 4242, 'Record 42 has been modified by patron 4242 yesterday'),
87 (?, 43, 'CATALOGUING', 'MODIFY', 4242, 'Record 43 has been modified by patron 4242 today')
88 |, undef, output_pref({dt =>$yesterday, dateformat => 'iso'}), output_pref({dt => $today, dateformat => 'iso'}));
89 my $logs = GetLogs( undef, undef, undef, ['CATALOGUING'], ['MODIFY'], 4242 );
90 is( scalar(@$logs), 2, 'GetLogs should return all logs regardless the dates' );
91 $logs = GetLogs( output_pref($today), undef, undef, ['CATALOGUING'], ['MODIFY'], 4242 );
92 is( scalar(@$logs), 1, 'GetLogs should return the logs for today' );