|
Lines 18-24
Link Here
|
| 18 |
# Add more tests here!!! |
18 |
# Add more tests here!!! |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use Test::More tests => 10; |
21 |
use Test::More tests => 5; |
| 22 |
|
22 |
|
| 23 |
use C4::Context; |
23 |
use C4::Context; |
| 24 |
use Koha::Database; |
24 |
use Koha::Database; |
|
Lines 29-35
use t::lib::Mocks qw/mock_preference/; # to mock CronjobLog
Link Here
|
| 29 |
$| = 1; |
29 |
$| = 1; |
| 30 |
|
30 |
|
| 31 |
BEGIN { |
31 |
BEGIN { |
| 32 |
use_ok('C4::Log'); |
32 |
use_ok('C4::Log'); |
| 33 |
} |
33 |
} |
| 34 |
my $success; |
34 |
my $success; |
| 35 |
|
35 |
|
|
Lines 38-92
my $schema = Koha::Database->new->schema;
Link Here
|
| 38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
| 39 |
my $dbh = C4::Context->dbh; |
39 |
my $dbh = C4::Context->dbh; |
| 40 |
|
40 |
|
| 41 |
eval { |
41 |
subtest 'Existing tests' => sub { |
| 42 |
# FIXME: are we sure there is an member number 1? |
42 |
plan tests => 6; |
| 43 |
logaction("MEMBERS","MODIFY",1,"test operation"); |
43 |
|
| 44 |
$success = 1; |
44 |
eval { |
| 45 |
} or do { |
45 |
# FIXME: are we sure there is an member number 1? |
| 46 |
diag($@); |
46 |
logaction("MEMBERS","MODIFY",1,"test operation"); |
| 47 |
$success = 0; |
47 |
$success = 1; |
| 48 |
}; |
48 |
} or do { |
| 49 |
ok($success, "logaction seemed to work"); |
49 |
diag($@); |
| 50 |
|
50 |
$success = 0; |
| 51 |
eval { |
51 |
}; |
| 52 |
# FIXME: US formatted date hardcoded into test for now |
52 |
ok($success, "logaction seemed to work"); |
| 53 |
$success = scalar(@{GetLogs("","","",undef,undef,"","")}); |
53 |
|
| 54 |
} or do { |
54 |
eval { |
| 55 |
diag($@); |
55 |
# FIXME: US formatted date hardcoded into test for now |
| 56 |
$success = 0; |
56 |
$success = scalar(@{GetLogs("","","",undef,undef,"","")}); |
| 57 |
}; |
57 |
} or do { |
| 58 |
ok($success, "GetLogs returns results for an open search"); |
58 |
diag($@); |
| 59 |
|
59 |
$success = 0; |
| 60 |
eval { |
60 |
}; |
| 61 |
# FIXME: US formatted date hardcoded into test for now |
61 |
ok($success, "GetLogs returns results for an open search"); |
| 62 |
my $date = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); |
62 |
|
| 63 |
$success = scalar(@{GetLogs( $date, $date, "", undef, undef, "", "") } ); |
63 |
eval { |
| 64 |
} or do { |
64 |
# FIXME: US formatted date hardcoded into test for now |
| 65 |
diag($@); |
65 |
my $date = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); |
| 66 |
$success = 0; |
66 |
$success = scalar(@{GetLogs( $date, $date, "", undef, undef, "", "") } ); |
| 67 |
}; |
67 |
} or do { |
| 68 |
ok($success, "GetLogs accepts dates in an All-matching search"); |
68 |
diag($@); |
| 69 |
|
69 |
$success = 0; |
| 70 |
eval { |
70 |
}; |
| 71 |
$success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")}); |
71 |
ok($success, "GetLogs accepts dates in an All-matching search"); |
| 72 |
} or do { |
72 |
|
| 73 |
diag($@); |
73 |
eval { |
| 74 |
$success = 0; |
74 |
$success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")}); |
| 75 |
}; |
75 |
} or do { |
| 76 |
ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search"); |
76 |
diag($@); |
| 77 |
|
77 |
$success = 0; |
| 78 |
# We want numbers to be the same between runs. |
78 |
}; |
| 79 |
$dbh->do("DELETE FROM action_logs;"); |
79 |
ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search"); |
|
|
80 |
|
| 81 |
# We want numbers to be the same between runs. |
| 82 |
$dbh->do("DELETE FROM action_logs;"); |
| 80 |
|
83 |
|
| 81 |
t::lib::Mocks::mock_preference('CronjobLog',0); |
84 |
t::lib::Mocks::mock_preference('CronjobLog',0); |
| 82 |
cronlogaction(); |
85 |
cronlogaction(); |
| 83 |
my $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{}); |
86 |
my $cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{}); |
| 84 |
is($cronJobCount,0,"Cronjob not logged as expected."); |
87 |
is($cronJobCount,0,"Cronjob not logged as expected."); |
| 85 |
|
88 |
|
| 86 |
t::lib::Mocks::mock_preference('CronjobLog',1); |
89 |
t::lib::Mocks::mock_preference('CronjobLog',1); |
| 87 |
cronlogaction(); |
90 |
cronlogaction(); |
| 88 |
$cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{}); |
91 |
$cronJobCount = $dbh->selectrow_array("SELECT COUNT(*) FROM action_logs WHERE module='CRONJOBS';",{}); |
| 89 |
is($cronJobCount,1,"Cronjob logged as expected."); |
92 |
is($cronJobCount,1,"Cronjob logged as expected."); |
|
|
93 |
}; |
| 90 |
|
94 |
|
| 91 |
subtest "GetLogs should return all logs if dates are not set" => sub { |
95 |
subtest "GetLogs should return all logs if dates are not set" => sub { |
| 92 |
plan tests => 2; |
96 |
plan tests => 2; |
| 93 |
- |
|
|