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

(-)a/t/db_dependent/Context.t (-34 / +39 lines)
Lines 7-28 use Test::MockModule; Link Here
7
use t::lib::Mocks;
7
use t::lib::Mocks;
8
use t::lib::TestBuilder;
8
use t::lib::TestBuilder;
9
9
10
use C4::Context;
10
use Koha::Database;
11
use Koha::Database;
11
12
12
BEGIN {
13
our $schema;
13
    my $ret;
14
$schema = Koha::Database->new->schema;
15
16
subtest 'Environment' => sub {
17
    plan tests => 2;
14
    # First we need to check your environmental variables
18
    # First we need to check your environmental variables
19
    my $ret;
15
    for (qw(KOHA_CONF PERL5LIB)) {
20
    for (qw(KOHA_CONF PERL5LIB)) {
16
        ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
21
        ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
17
    }
22
    }
18
    use_ok('C4::Context');
23
};
19
}
20
21
our $schema;
22
$schema = Koha::Database->new->schema;
23
24
24
subtest 'Original tests' => sub {
25
subtest 'Tests with preferences' => sub {
25
    plan tests => 33;
26
    plan tests => 22;
26
    $schema->storage->txn_begin;
27
    $schema->storage->txn_begin;
27
28
28
    my $dbh;
29
    my $dbh;
Lines 54-78 subtest 'Original tests' => sub { Link Here
54
    C4::Context->clear_syspref_cache();
55
    C4::Context->clear_syspref_cache();
55
    C4::Context->enable_syspref_cache();
56
    C4::Context->enable_syspref_cache();
56
57
57
    my $koha;
58
    ok($koha = C4::Context->new,  'C4::Context->new');
59
    my @keys = keys %$koha;
60
    my $width = 0;
61
    ok( @keys, 'Expecting entries in context hash' );
62
    if( @keys ) {
63
        $width = (sort {$a <=> $b} map {length} @keys)[-1];
64
    }
65
    foreach (sort @keys) {
66
        ok(exists $koha->{$_},
67
            '$koha->{' . sprintf('%' . $width . 's', $_)  . '} exists '
68
            . ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
69
        );
70
    }
71
    my $config;
72
    ok($config = $koha->{config}, 'Getting $koha->{config} ');
73
74
    # Testing syspref caching
58
    # Testing syspref caching
75
76
    $schema->storage->debug(1);
59
    $schema->storage->debug(1);
77
    my $trace_read;
60
    my $trace_read;
78
    open my $trace, '>', \$trace_read or die "Can't open variable: $!";
61
    open my $trace, '>', \$trace_read or die "Can't open variable: $!";
Lines 116-127 subtest 'Original tests' => sub { Link Here
116
    is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
99
    is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
117
    is( $trace_read, q{}, 'Did not retrieve syspref from database');
100
    is( $trace_read, q{}, 'Did not retrieve syspref from database');
118
    $trace_read = q{};
101
    $trace_read = q{};
119
120
    my $oConnection = C4::Context->Zconn('biblioserver', 0);
121
    isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
122
    $oConnection = C4::Context->Zconn('biblioserver', 1);
123
    is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
124
125
    $silly_preference->delete();
102
    $silly_preference->delete();
126
103
127
    # AutoEmailNewUser should be a YesNo pref
104
    # AutoEmailNewUser should be a YesNo pref
Lines 131-133 subtest 'Original tests' => sub { Link Here
131
108
132
    $schema->storage->txn_rollback;
109
    $schema->storage->txn_rollback;
133
};
110
};
134
- 
111
112
subtest 'Check context hash keys' => sub {
113
    my $koha;
114
    ok($koha = C4::Context->new, 'C4::Context->new');
115
    my @keys = keys %$koha;
116
    my $width = 0;
117
    ok( @keys, 'Expecting entries in context hash' );
118
    if( @keys ) {
119
        $width = (sort {$a <=> $b} map {length} @keys)[-1];
120
    }
121
    foreach (sort @keys) {
122
        ok(exists $koha->{$_},
123
            '$koha->{' . sprintf('%' . $width . 's', $_)  . '} exists '
124
            . ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
125
        );
126
    }
127
    my $config;
128
    ok($config = $koha->{config}, 'Getting $koha->{config} ');
129
    done_testing();
130
};
131
132
subtest 'Zconn' => sub {
133
    plan tests => 2;
134
    my $oConnection = C4::Context->Zconn('biblioserver', 0);
135
    isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
136
    $oConnection = C4::Context->Zconn('biblioserver', 1);
137
    is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
138
139
};

Return to bug 31870