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
($koha = C4
::Context
->new, 'C4::Context->new');
22 ok
($dbh = C4
::Context
->dbh(), 'Getting dbh from C4::Context');
23 my @keys = keys %$koha;
26 $width = (sort {$a <=> $b} map {length} @keys)[-1];
27 $debug and diag
"widest key is $width";
29 foreach (sort @keys) {
30 ok
(exists $koha->{$_},
31 '$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
32 . ((defined $koha->{$_}) ?
"and is defined." : "but is not defined.")
35 ok
($config = $koha->{config
}, 'Getting $koha->{config} ');
37 # Testing syspref caching
38 my $module = new Test
::MockModule
('C4::Context');
42 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
43 || die "Cannot create handle: $DBI::errstr\n";
49 $dbh = C4
::Context
->dbh({ new
=> 1 });
51 $dbh->{mock_add_resultset
} = [ ['value'], ['thing1'] ];
52 $dbh->{mock_add_resultset
} = [ ['value'], ['thing2'] ];
53 $dbh->{mock_add_resultset
} = [ ['value'], ['thing3'] ];
54 $dbh->{mock_add_resultset
} = [ ['value'], ['thing4'] ];
56 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
57 $history = $dbh->{mock_all_history
};
58 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
60 $dbh->{mock_clear_history
} = 1;
61 is
(C4
::Context
->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior");
62 $history = $dbh->{mock_all_history
};
63 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
65 C4
::Context
->disable_syspref_cache();
66 is
(C4
::Context
->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache");
67 $history = $dbh->{mock_all_history
};
68 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
70 $dbh->{mock_clear_history
} = 1;
71 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache");
72 $history = $dbh->{mock_all_history
};
73 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
75 C4
::Context
->enable_syspref_cache();
76 $dbh->{mock_clear_history
} = 1;
77 is
(C4
::Context
->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache");
78 $history = $dbh->{mock_all_history
};
79 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
81 C4
::Context
->clear_syspref_cache();
82 $dbh->{mock_clear_history
} = 1;
83 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache");
84 $history = $dbh->{mock_all_history
};
85 is
(scalar(@
{$history}), 1, 'Retrieved syspref from database');
87 $dbh->{mock_clear_history
} = 1;
88 is
(C4
::Context
->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
89 $history = $dbh->{mock_all_history
};
90 is
(scalar(@
{$history}), 0, 'Did not retrieve syspref from database');
92 my $oConnection = C4
::Context
->Zconn('biblioserver', 0);
93 isnt
($oConnection->option('async'), 1, "ZOOM connection is synchronous");
94 $oConnection = C4
::Context
->Zconn('biblioserver', 1);
95 is
($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
99 sub TransformVersionToNum
{
102 # remove the 3 last . to have a Perl number
103 $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
105 # three X's at the end indicate that you are testing patch with dbrev
107 # prevents error on a < comparison between strings (should be: lt)
108 $version =~ s/XXX$/999/;