Lines 8-13
use vars qw($debug $koha $dbh $config $ret);
Link Here
|
8 |
use t::lib::Mocks; |
8 |
use t::lib::Mocks; |
9 |
|
9 |
|
10 |
use Koha::Database; |
10 |
use Koha::Database; |
|
|
11 |
use Koha::Caches; |
11 |
|
12 |
|
12 |
BEGIN { |
13 |
BEGIN { |
13 |
$debug = $ENV{DEBUG} || 0; |
14 |
$debug = $ENV{DEBUG} || 0; |
Lines 48-53
my $SillyPeference = C4::Context->preference('SillyPreference');
Link Here
|
48 |
is($SillyPeference,'random','SillyPreference saved as specified'); |
49 |
is($SillyPeference,'random','SillyPreference saved as specified'); |
49 |
C4::Context->clear_syspref_cache(); |
50 |
C4::Context->clear_syspref_cache(); |
50 |
C4::Context->enable_syspref_cache(); |
51 |
C4::Context->enable_syspref_cache(); |
|
|
52 |
|
53 |
subtest 'test system preference of type YAML or JSON' => sub { |
54 |
my ($hashref, $arrayref, $string, $pref); |
55 |
my $cache = Koha::Caches->get_instance('syspref'); |
56 |
|
57 |
subtest 'Invalid syntax' => sub { |
58 |
my $notyaml = ': - asd'; |
59 |
my $notjson = '{"test"": { "fail\' ]}'; |
60 |
eval { |
61 |
C4::Context->set_preference('YAMLpref', $notyaml, '', 'yaml', ''); |
62 |
}; |
63 |
is(ref($@), 'Koha::Exceptions::Config::InvalidSyntax', |
64 |
'Invalid YAML syntax'); |
65 |
eval { |
66 |
C4::Context->set_preference('YAMLpref', $notjson, '', 'json', ''); |
67 |
}; |
68 |
is(ref($@), 'Koha::Exceptions::Config::InvalidSyntax', |
69 |
'Invalid JSON syntax'); |
70 |
C4::Context->set_preference('Normalpref', $notyaml, '', 'Free', ''); |
71 |
is(C4::Context->preference('Normalpref'), $notyaml, 'Does not affect ' |
72 |
.'preferences with type != json || yaml'); |
73 |
}; |
74 |
|
75 |
subtest 'test YAML' => sub { |
76 |
plan skip_all => 'Cache not active' unless $cache->is_cache_active(); |
77 |
|
78 |
$hashref = qq/--- |
79 |
test: |
80 |
test: 1 |
81 |
/; |
82 |
$arrayref = qq/--- |
83 |
[much, elements, in, this, very, dogearray] |
84 |
/; |
85 |
$string = qq/--- |
86 |
wat |
87 |
/; |
88 |
|
89 |
# Check HASHref |
90 |
C4::Context->set_preference('YAMLpref', $hashref, '', 'yaml', ''); |
91 |
$pref = C4::Context->preference('YAMLpref'); |
92 |
is($pref->{test}->{test}, 1, 'Got hashref'); |
93 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
94 |
|
95 |
# Check ARRAYref |
96 |
C4::Context->set_preference('YAMLpref', $arrayref, '', 'yaml', ''); |
97 |
$pref = C4::Context->preference('YAMLpref'); |
98 |
is($pref->[5], 'dogearray', 'Got arrayref'); |
99 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
100 |
|
101 |
# Check string |
102 |
C4::Context->set_preference('YAMLpref', $string, '', 'yaml', ''); |
103 |
$pref = C4::Context->preference('YAMLpref'); |
104 |
is($pref, 'wat', 'Got string'); |
105 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
106 |
}; |
107 |
subtest 'test JSON' => sub { |
108 |
plan skip_all => 'Cache not active' unless $cache->is_cache_active(); |
109 |
|
110 |
$hashref = qq/{"test": {"test": 1}}/; |
111 |
$arrayref = qq/["much", "elements", "in", "this", "very", "dogearray"]/; |
112 |
$string = qq/"wat"/; |
113 |
|
114 |
# Check HASHref |
115 |
C4::Context->set_preference('JSONpref', $hashref, '', 'json', ''); |
116 |
$pref = C4::Context->preference('JSONpref'); |
117 |
is($pref->{test}->{test}, 1, 'Got hashref'); |
118 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
119 |
|
120 |
# Check ARRAYref |
121 |
C4::Context->set_preference('JSONpref', $arrayref, '', 'json', ''); |
122 |
$pref = C4::Context->preference('JSONpref'); |
123 |
is($pref->[5], 'dogearray', 'Got arrayref'); |
124 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
125 |
|
126 |
# Check string |
127 |
C4::Context->set_preference('JSONpref', $string, '', 'json', ''); |
128 |
$pref = C4::Context->preference('JSONpref'); |
129 |
is($pref, 'wat', 'Got string'); |
130 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
131 |
}; |
132 |
}; |
133 |
|
51 |
$dbh->rollback; |
134 |
$dbh->rollback; |
52 |
|
135 |
|
53 |
ok($koha = C4::Context->new, 'C4::Context->new'); |
136 |
ok($koha = C4::Context->new, 'C4::Context->new'); |
Lines 63-135
foreach (sort @keys) {
Link Here
|
63 |
. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.") |
146 |
. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.") |
64 |
); |
147 |
); |
65 |
} |
148 |
} |
66 |
ok($config = $koha->{config}, 'Getting $koha->{config} '); |
|
|
67 |
|
149 |
|
68 |
# Testing syspref caching |
150 |
subtest 'test system preference caching' => sub { |
69 |
use Test::DBIx::Class; |
151 |
my $cache = Koha::Caches->get_instance('syspref'); |
|
|
152 |
plan skip_all => 'Cache not active' unless $cache->is_cache_active(); |
70 |
|
153 |
|
71 |
my $history; |
154 |
ok($config = $koha->{config}, 'Getting $koha->{config} '); |
72 |
|
155 |
|
73 |
my $schema = Koha::Database->new()->schema(); |
156 |
use Test::DBIx::Class; |
74 |
$schema->storage->debug(1); |
|
|
75 |
my $trace_read; |
76 |
open my $trace, '>', \$trace_read or die "Can't open variable: $!"; |
77 |
$schema->storage->debugfh( $trace ); |
78 |
|
157 |
|
79 |
C4::Context->set_preference('SillyPreference', 'thing1'); |
158 |
my $history; |
80 |
my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference'); |
|
|
81 |
is( $silly_preference->variable, 'SillyPreference', 'set_preference should have kept the case sensitivity' ); |
82 |
|
159 |
|
83 |
my $pref = C4::Context->preference("SillyPreference"); |
160 |
my $schema = Koha::Database->new()->schema(); |
84 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
161 |
$schema->storage->debug(1); |
85 |
ok( $trace_read, 'Retrieved syspref from database'); |
162 |
my $trace_read; |
86 |
$trace_read = q{}; |
163 |
open my $trace, '>', \$trace_read or die "Can't open variable: $!"; |
|
|
164 |
$schema->storage->debugfh( $trace ); |
87 |
|
165 |
|
88 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
166 |
C4::Context->set_preference('SillyPreference', 'thing1'); |
89 |
is( $trace_read , q{}, 'Did not retrieve syspref from database'); |
167 |
my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference'); |
90 |
$trace_read = q{}; |
168 |
is( $silly_preference->variable, 'SillyPreference', 'set_preference should have kept the case sensitivity' ); |
91 |
|
169 |
|
92 |
C4::Context->disable_syspref_cache(); |
170 |
my $pref = C4::Context->preference("SillyPreference"); |
93 |
$silly_preference->set( { value => 'thing2' } )->store(); |
171 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
94 |
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache"); |
172 |
ok( $trace_read, 'Retrieved syspref from database'); |
95 |
ok($trace_read, 'Retrieved syspref from database'); |
173 |
$trace_read = q{}; |
96 |
$trace_read = q{}; |
|
|
97 |
|
174 |
|
98 |
$silly_preference->set( { value => 'thing3' } )->store(); |
175 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
99 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache"); |
176 |
is( $trace_read , q{}, 'Did not retrieve syspref from database'); |
100 |
ok($trace_read, 'Retrieved syspref from database'); |
177 |
$trace_read = q{}; |
101 |
$trace_read = q{}; |
|
|
102 |
|
178 |
|
103 |
C4::Context->enable_syspref_cache(); |
179 |
C4::Context->disable_syspref_cache(); |
104 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache"); |
180 |
$silly_preference->set( { value => 'thing2' } )->store(); |
105 |
isnt( $trace_read, q{}, 'The pref should be retrieved from the database if the cache has been enabled'); |
181 |
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache"); |
106 |
$trace_read = q{}; |
182 |
ok($trace_read, 'Retrieved syspref from database'); |
107 |
|
183 |
$trace_read = q{}; |
108 |
# FIXME This was added by Robin and does not pass anymore |
184 |
|
109 |
# I don't understand why we should expect thing1 while thing3 is in the cache and in the DB |
185 |
$silly_preference->set( { value => 'thing3' } )->store(); |
110 |
#$dbh->{mock_clear_history} = 1; |
186 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache"); |
111 |
## This gives us the value that was cached on the first call, when the cache was active. |
187 |
ok($trace_read, 'Retrieved syspref from database'); |
112 |
#is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully from cache"); |
188 |
$trace_read = q{}; |
113 |
#$history = $dbh->{mock_all_history}; |
|
|
114 |
#is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); |
115 |
|
116 |
$silly_preference->set( { value => 'thing4' } )->store(); |
117 |
C4::Context->clear_syspref_cache(); |
118 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache"); |
119 |
ok($trace_read, 'Retrieved syspref from database'); |
120 |
$trace_read = q{}; |
121 |
|
189 |
|
122 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache"); |
190 |
C4::Context->enable_syspref_cache(); |
123 |
is( $trace_read, q{}, 'Did not retrieve syspref from database'); |
191 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache"); |
124 |
$trace_read = q{}; |
192 |
isnt( $trace_read, q{}, 'The pref should be retrieved from the database if the cache has been enabled'); |
|
|
193 |
$trace_read = q{}; |
194 |
|
195 |
# FIXME This was added by Robin and does not pass anymore |
196 |
# I don't understand why we should expect thing1 while thing3 is in the cache and in the DB |
197 |
#$dbh->{mock_clear_history} = 1; |
198 |
## This gives us the value that was cached on the first call, when the cache was active. |
199 |
#is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully from cache"); |
200 |
#$history = $dbh->{mock_all_history}; |
201 |
#is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); |
202 |
|
203 |
$silly_preference->set( { value => 'thing4' } )->store(); |
204 |
C4::Context->clear_syspref_cache(); |
205 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache"); |
206 |
ok($trace_read, 'Retrieved syspref from database'); |
207 |
$trace_read = q{}; |
208 |
|
209 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache"); |
210 |
is( $trace_read, q{}, 'Did not retrieve syspref from database'); |
211 |
$trace_read = q{}; |
212 |
|
213 |
$silly_preference->delete(); |
214 |
}; |
125 |
|
215 |
|
126 |
my $oConnection = C4::Context->Zconn('biblioserver', 0); |
216 |
my $oConnection = C4::Context->Zconn('biblioserver', 0); |
127 |
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous"); |
217 |
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous"); |
128 |
$oConnection = C4::Context->Zconn('biblioserver', 1); |
218 |
$oConnection = C4::Context->Zconn('biblioserver', 1); |
129 |
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous"); |
219 |
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous"); |
130 |
|
220 |
|
131 |
$silly_preference->delete(); |
|
|
132 |
|
133 |
# AutoEmailOpacUser should be a YesNo pref |
221 |
# AutoEmailOpacUser should be a YesNo pref |
134 |
C4::Context->set_preference('AutoEmailOpacUser', ''); |
222 |
C4::Context->set_preference('AutoEmailOpacUser', ''); |
135 |
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); |
223 |
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailOpacUser'); |
136 |
- |
|
|