View | Details | Raw Unified | Return to bug 21190
Collapse All | Expand All

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

Return to bug 21190