9 use vars
qw($debug $koha $dbh $config $ret);
12 $debug = $ENV{DEBUG} || 0;
13 # Note: The overall number of tests may vary by configuration.
14 # First we need to check your environmental variables
15 for (qw(KOHA_CONF PERL5LIB)) {
16 ok
($ret = $ENV{$_}, "ENV{$_} = $ret");
18 use_ok
('C4::Context');
21 ok
($dbh = C4
::Context
->dbh(), 'Getting dbh from C4::Context');
24 C4
::Context
->disable_syspref_cache();
25 C4
::Context
->set_preference('OPACBaseURL','junk');
26 C4
::Context
->clear_syspref_cache();
27 my $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
28 is
($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it');
30 C4
::Context
->set_preference('OPACBaseURL','https://junk');
31 C4
::Context
->clear_syspref_cache();
32 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
33 is
($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified');
35 C4
::Context
->set_preference('OPACBaseURL','http://junk2');
36 C4
::Context
->clear_syspref_cache();
37 $OPACBaseURL = C4
::Context
->preference('OPACBaseURL');
38 is
($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified');
40 C4
::Context
->set_preference('SillyPreference','random');
41 C4
::Context
->clear_syspref_cache();
42 my $SillyPeference = C4
::Context
->preference('SillyPreference');
43 is
($SillyPeference,'random','SillyPreference saved as specified');
44 C4
::Context
->clear_syspref_cache();
45 C4
::Context
->enable_syspref_cache();
48 ok
($koha = C4
::Context
->new, 'C4::Context->new');
49 my @keys = keys %$koha;
52 $width = (sort {$a <=> $b} map {length} @keys)[-1];
53 $debug and diag
"widest key is $width";
55 foreach (sort @keys) {
56 ok
(exists $koha->{$_},
57 '$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
58 . ((defined $koha->{$_}) ?
"and is defined." : "but is not defined.")
61 ok
($config = $koha->{config
}, 'Getting $koha->{config} ');
63 # Testing syspref caching
64 my $module = new Test
::MockModule
('C4::Context');
68 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
69 || die "Cannot create handle: $DBI::errstr\n";
75 $dbh = C4
::Context
->dbh({ new
=> 1 });
77 $dbh->{mock_add_resultset
} = [ ['value'], ['thing1'] ];
78 $dbh->{mock_add_resultset
} = [ ['value'], ['thing2'] ];
79 $dbh->{mock_add_resultset
} = [ ['value'], ['thing3'] ];
80 $dbh->{mock_add_resultset
} = [ ['value'], ['thing4'] ];
82 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
83 $history = $dbh->{mock_all_history
};
84 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
86 $dbh->{mock_clear_history
} = 1;
87 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
88 $history = $dbh->{mock_all_history
};
89 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
91 C4
::Context
->disable_syspref_cache();
92 is
(C4
::Context
->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
93 $history = $dbh->{mock_all_history
};
94 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
96 $dbh->{mock_clear_history
} = 1;
97 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
98 $history = $dbh->{mock_all_history
};
99 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
101 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");
104 $history = $dbh->{mock_all_history
};
105 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
107 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");
110 $history = $dbh->{mock_all_history
};
111 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
113 $dbh->{mock_clear_history
} = 1;
114 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
115 $history = $dbh->{mock_all_history
};
116 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
118 my $oConnection = C4
::Context
->Zconn('biblioserver', 0);
119 isnt
($oConnection->option('async'), 1, "ZOOM connection is synchronous");
120 $oConnection = C4
::Context
->Zconn('biblioserver', 1);
121 is
($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
125 sub TransformVersionToNum
{
128 # remove the 3 last . to have a Perl number
129 $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
131 # three X's at the end indicate that you are testing patch with dbrev
133 # prevents error on a < comparison between strings (should be: lt)
134 $version =~ s/XXX$/999/;