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 |
$hashref = qq/--- |
77 |
test: |
78 |
test: 1 |
79 |
/; |
80 |
$arrayref = qq/--- |
81 |
[much, elements, in, this, very, dogearray] |
82 |
/; |
83 |
$string = qq/--- |
84 |
wat |
85 |
/; |
86 |
|
87 |
# Check HASHref |
88 |
C4::Context->set_preference('YAMLpref', $hashref, '', 'yaml', ''); |
89 |
$pref = C4::Context->preference('YAMLpref'); |
90 |
is($pref->{test}->{test}, 1, 'Got hashref'); |
91 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
92 |
|
93 |
# Check ARRAYref |
94 |
C4::Context->set_preference('YAMLpref', $arrayref, '', 'yaml', ''); |
95 |
$pref = C4::Context->preference('YAMLpref'); |
96 |
is($pref->[5], 'dogearray', 'Got arrayref'); |
97 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
98 |
|
99 |
# Check string |
100 |
C4::Context->set_preference('YAMLpref', $string, '', 'yaml', ''); |
101 |
$pref = C4::Context->preference('YAMLpref'); |
102 |
is($pref, 'wat', 'Got string'); |
103 |
is_deeply($cache->get_from_cache("syspref_yamlpref"), $pref, 'is_deeply'); |
104 |
}; |
105 |
subtest 'test JSON' => sub { |
106 |
$hashref = qq/{"test": {"test": 1}}/; |
107 |
$arrayref = qq/["much", "elements", "in", "this", "very", "dogearray"]/; |
108 |
$string = qq/"wat"/; |
109 |
|
110 |
# Check HASHref |
111 |
C4::Context->set_preference('JSONpref', $hashref, '', 'json', ''); |
112 |
$pref = C4::Context->preference('JSONpref'); |
113 |
is($pref->{test}->{test}, 1, 'Got hashref'); |
114 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
115 |
|
116 |
# Check ARRAYref |
117 |
C4::Context->set_preference('JSONpref', $arrayref, '', 'json', ''); |
118 |
$pref = C4::Context->preference('JSONpref'); |
119 |
is($pref->[5], 'dogearray', 'Got arrayref'); |
120 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
121 |
|
122 |
# Check string |
123 |
C4::Context->set_preference('JSONpref', $string, '', 'json', ''); |
124 |
$pref = C4::Context->preference('JSONpref'); |
125 |
is($pref, 'wat', 'Got string'); |
126 |
is_deeply($cache->get_from_cache("syspref_jsonpref"), $pref, 'is_deeply'); |
127 |
}; |
128 |
}; |
129 |
|
51 |
$dbh->rollback; |
130 |
$dbh->rollback; |
52 |
|
131 |
|
53 |
ok($koha = C4::Context->new, 'C4::Context->new'); |
132 |
ok($koha = C4::Context->new, 'C4::Context->new'); |
54 |
- |
|
|