8 use vars
qw($debug $koha $dbh $config $ret);
13 $debug = $ENV{DEBUG} || 0;
15 # Note: The overall number of tests may vary by configuration.
16 # First we need to check your environmental variables
17 for (qw(KOHA_CONF PERL5LIB)) {
18 ok
( $ret = $ENV{$_}, "ENV{$_} = $ret" );
20 use_ok
('C4::Context');
23 ok
($dbh = C4
::Context
->dbh(), 'Getting dbh from C4::Context');
26 C4
::Context
->disable_syspref_cache();
27 C4
::Context
->set_preference('OPACBaseURL','junk');
28 C4
::Context
->clear_syspref_cache();
29 my $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
30 is
($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it');
32 C4
::Context
->set_preference('OPACBaseURL','https://junk');
33 C4
::Context
->clear_syspref_cache();
34 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
35 is
($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified');
37 C4
::Context
->set_preference('OPACBaseURL','http://junk2');
38 C4
::Context
->clear_syspref_cache();
39 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
40 is
($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified');
42 C4
::Context
->set_preference('SillyPreference','random');
43 C4
::Context
->clear_syspref_cache();
44 my $SillyPeference = C4
::Context
->preference('SillyPreference');
45 is
($SillyPeference,'random','SillyPreference saved as specified');
46 C4
::Context
->clear_syspref_cache();
47 C4
::Context
->enable_syspref_cache();
50 ok
($koha = C4
::Context
->new, 'C4::Context->new');
51 my @keys = keys %$koha;
54 $width = (sort {$a <=> $b} map {length} @keys)[-1];
55 $debug and diag
"widest key is $width";
57 foreach (sort @keys) {
58 ok
(exists $koha->{$_},
59 '$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
60 . ((defined $koha->{$_}) ?
"and is defined." : "but is not defined.")
63 ok
($config = $koha->{config
}, 'Getting $koha->{config} ');
65 # Testing syspref caching
66 my $module = new Test
::MockModule
('C4::Context');
70 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
71 || die "Cannot create handle: $DBI::errstr\n";
78 my $schema = Koha
::Database
->new()->schema();
79 $schema->storage->debug(1);
81 open my $trace, '>', \
$trace_read or die "Can't open variable: $!";
82 $schema->storage->debugfh( $trace );
84 C4
::Context
->set_preference('SillyPreference', 'thing1');
85 my $silly_preference = Koha
::Config
::SysPrefs
->find('SillyPreference');
87 my $pref = C4
::Context
->preference("SillyPreference");
88 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
89 ok
( $trace_read, 'Retrieved syspref from database');
92 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
93 is
( $trace_read , q{}, 'Did not retrieve syspref from database');
96 C4
::Context
->disable_syspref_cache();
97 $silly_preference->set( { value
=> 'thing2' } )->store();
98 is
(C4
::Context
->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
99 ok
($trace_read, 'Retrieved syspref from database');
102 $silly_preference->set( { value
=> 'thing3' } )->store();
103 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
104 ok
($trace_read, 'Retrieved syspref from database');
107 C4
::Context
->enable_syspref_cache();
108 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
109 is
( $trace_read, q{}, 'Did not retrieve syspref from database');
112 $silly_preference->set( { value
=> 'thing4' } )->store();
113 C4
::Context
->clear_syspref_cache();
114 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache");
115 ok
($trace_read, 'Retrieved syspref from database');
118 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
119 is
( $trace_read, q{}, 'Did not retrieve syspref from database');
122 my $oConnection = C4
::Context
->Zconn('biblioserver', 0);
123 isnt
($oConnection->option('async'), 1, "ZOOM connection is synchronous");
124 $oConnection = C4
::Context
->Zconn('biblioserver', 1);
125 is
($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
127 $silly_preference->delete();
131 sub TransformVersionToNum
{
134 # remove the 3 last . to have a Perl number
135 $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
137 # three X's at the end indicate that you are testing patch with dbrev
139 # prevents error on a < comparison between strings (should be: lt)
140 $version =~ s/XXX$/999/;