8 use vars
qw($debug $koha $dbh $config $ret);
14 $debug = $ENV{DEBUG} || 0;
16 # Note: The overall number of tests may vary by configuration.
17 # First we need to check your environmental variables
18 for (qw(KOHA_CONF PERL5LIB)) {
19 ok
( $ret = $ENV{$_}, "ENV{$_} = $ret" );
21 use_ok
('C4::Context');
24 ok
($dbh = C4
::Context
->dbh(), 'Getting dbh from C4::Context');
27 C4
::Context
->disable_syspref_cache();
28 C4
::Context
->set_preference('OPACBaseURL','junk');
29 C4
::Context
->clear_syspref_cache();
30 my $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
31 is
($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it');
33 C4
::Context
->set_preference('OPACBaseURL','https://junk');
34 C4
::Context
->clear_syspref_cache();
35 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
36 is
($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified');
38 C4
::Context
->set_preference('OPACBaseURL','http://junk2');
39 C4
::Context
->clear_syspref_cache();
40 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
41 is
($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified');
43 C4
::Context
->set_preference('SillyPreference','random');
44 C4
::Context
->clear_syspref_cache();
45 my $SillyPeference = C4
::Context
->preference('SillyPreference');
46 is
($SillyPeference,'random','SillyPreference saved as specified');
47 C4
::Context
->clear_syspref_cache();
48 C4
::Context
->enable_syspref_cache();
51 ok
($koha = C4
::Context
->new, 'C4::Context->new');
52 my @keys = keys %$koha;
55 $width = (sort {$a <=> $b} map {length} @keys)[-1];
56 $debug and diag
"widest key is $width";
58 foreach (sort @keys) {
59 ok
(exists $koha->{$_},
60 '$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
61 . ((defined $koha->{$_}) ?
"and is defined." : "but is not defined.")
64 ok
($config = $koha->{config
}, 'Getting $koha->{config} ');
66 # Testing syspref caching
67 t
::lib
::Mocks
::mock_dbh
;
71 my $schema = Koha
::Database
->new()->schema();
72 $schema->storage->debug(1);
74 open my $trace, '>', \
$trace_read or die "Can't open variable: $!";
75 $schema->storage->debugfh( $trace );
77 C4
::Context
->set_preference('SillyPreference', 'thing1');
78 my $silly_preference = Koha
::Config
::SysPrefs
->find('SillyPreference');
80 my $pref = C4
::Context
->preference("SillyPreference");
81 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
82 ok
( $trace_read, 'Retrieved syspref from database');
85 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
86 is
( $trace_read , q{}, 'Did not retrieve syspref from database');
89 C4
::Context
->disable_syspref_cache();
90 $silly_preference->set( { value
=> 'thing2' } )->store();
91 is
(C4
::Context
->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
92 ok
($trace_read, 'Retrieved syspref from database');
95 $silly_preference->set( { value
=> 'thing3' } )->store();
96 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
97 ok
($trace_read, 'Retrieved syspref from database');
100 C4
::Context
->enable_syspref_cache();
101 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
102 is
( $trace_read, q{}, 'Did not retrieve syspref from database');
105 $silly_preference->set( { value
=> 'thing4' } )->store();
106 C4
::Context
->clear_syspref_cache();
107 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache");
108 ok
($trace_read, 'Retrieved syspref from database');
111 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
112 is
( $trace_read, q{}, 'Did not retrieve syspref from database');
115 my $oConnection = C4
::Context
->Zconn('biblioserver', 0);
116 isnt
($oConnection->option('async'), 1, "ZOOM connection is synchronous");
117 $oConnection = C4
::Context
->Zconn('biblioserver', 1);
118 is
($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
120 $silly_preference->delete();
124 sub TransformVersionToNum
{
127 # remove the 3 last . to have a Perl number
128 $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
130 # three X's at the end indicate that you are testing patch with dbrev
132 # prevents error on a < comparison between strings (should be: lt)
133 $version =~ s/XXX$/999/;