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

(-)a/t/db_dependent/Context.t (-33 / +38 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
3
2
4
use strict;
3
use strict;
5
use warnings;
4
use warnings;
Lines 8-21 use Test::More; Link Here
8
use Test::MockModule;
7
use Test::MockModule;
9
use vars qw($debug $koha $dbh $config $ret);
8
use vars qw($debug $koha $dbh $config $ret);
10
9
10
use Koha::Database;
11
11
BEGIN {
12
BEGIN {
12
		$debug = $ENV{DEBUG} || 0;
13
    $debug = $ENV{DEBUG} || 0;
13
        # Note: The overall number of tests may vary by configuration.
14
14
        # First we need to check your environmental variables
15
    # Note: The overall number of tests may vary by configuration.
15
		for (qw(KOHA_CONF PERL5LIB)) {
16
    # First we need to check your environmental variables
16
			ok($ret = $ENV{$_}, "ENV{$_} = $ret");
17
    for (qw(KOHA_CONF PERL5LIB)) {
17
		}
18
        ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
18
		use_ok('C4::Context');
19
    }
20
    use_ok('C4::Context');
19
}
21
}
20
22
21
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
23
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
Lines 72-125 $module->mock( Link Here
72
);
74
);
73
75
74
my $history;
76
my $history;
75
$dbh = C4::Context->dbh({ new => 1 });
76
77
77
$dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ];
78
my $schema = Koha::Database->new()->schema();
78
$dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ];
79
$schema->storage->debug(1);
79
$dbh->{mock_add_resultset} = [ ['value'], ['thing3'] ];
80
my $trace_read;
80
$dbh->{mock_add_resultset} = [ ['value'], ['thing4'] ];
81
open my $trace, '>', \$trace_read or die "Can't open variable: $!";
82
$schema->storage->debugfh( $trace );
81
83
84
C4::Context->set_preference('SillyPreference', 'thing1');
85
my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference');
86
87
my $pref = C4::Context->preference("SillyPreference");
82
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
88
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
83
$history = $dbh->{mock_all_history};
89
ok( $trace_read, 'Retrieved syspref from database');
84
is(scalar(@{$history}), 1, 'Retrieved syspref from database');
90
$trace_read = q{};
85
91
86
$dbh->{mock_clear_history} = 1;
87
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
92
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
88
$history = $dbh->{mock_all_history};
93
is( $trace_read , q{}, 'Did not retrieve syspref from database');
89
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database');
94
$trace_read = q{};
90
95
91
C4::Context->disable_syspref_cache();
96
C4::Context->disable_syspref_cache();
97
$silly_preference->set( { value => 'thing2' } )->store();
92
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
98
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
93
$history = $dbh->{mock_all_history};
99
ok($trace_read, 'Retrieved syspref from database');
94
is(scalar(@{$history}), 1, 'Retrieved syspref from database');
100
$trace_read = q{};
95
101
96
$dbh->{mock_clear_history} = 1;
102
$silly_preference->set( { value => 'thing3' } )->store();
97
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
103
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
98
$history = $dbh->{mock_all_history};
104
ok($trace_read, 'Retrieved syspref from database');
99
is(scalar(@{$history}), 1, 'Retrieved syspref from database');
105
$trace_read = q{};
100
106
101
C4::Context->enable_syspref_cache();
107
C4::Context->enable_syspref_cache();
102
$dbh->{mock_clear_history} = 1;
103
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
108
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
104
$history = $dbh->{mock_all_history};
109
is( $trace_read, q{}, 'Did not retrieve syspref from database');
105
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database');
110
$trace_read = q{};
106
111
112
$silly_preference->set( { value => 'thing4' } )->store();
107
C4::Context->clear_syspref_cache();
113
C4::Context->clear_syspref_cache();
108
$dbh->{mock_clear_history} = 1;
109
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache");
114
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache");
110
$history = $dbh->{mock_all_history};
115
ok($trace_read, 'Retrieved syspref from database');
111
is(scalar(@{$history}), 1, 'Retrieved syspref from database');
116
$trace_read = q{};
112
117
113
$dbh->{mock_clear_history} = 1;
114
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
118
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
115
$history = $dbh->{mock_all_history};
119
is( $trace_read, q{}, 'Did not retrieve syspref from database');
116
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database');
120
$trace_read = q{};
117
121
118
my $oConnection = C4::Context->Zconn('biblioserver', 0);
122
my $oConnection = C4::Context->Zconn('biblioserver', 0);
119
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
123
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
120
$oConnection = C4::Context->Zconn('biblioserver', 1);
124
$oConnection = C4::Context->Zconn('biblioserver', 1);
121
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
125
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
122
126
127
$silly_preference->delete();
128
123
done_testing();
129
done_testing();
124
130
125
sub TransformVersionToNum {
131
sub TransformVersionToNum {
126
- 

Return to bug 14342