Lines 1-5
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
|
|
3 |
|
2 |
|
4 |
use strict; |
3 |
use strict; |
5 |
use warnings; |
4 |
use warnings; |
Lines 8-21
use Test::More;
Link Here
|
8 |
use Test::MockModule; |
7 |
use Test::MockModule; |
9 |
use vars qw($debug $koha $dbh $config $ret); |
8 |
use vars qw($debug $koha $dbh $config $ret); |
10 |
|
9 |
|
|
|
10 |
use Koha::Database; |
11 |
|
11 |
BEGIN { |
12 |
BEGIN { |
12 |
$debug = $ENV{DEBUG} || 0; |
13 |
$debug = $ENV{DEBUG} || 0; |
13 |
# Note: The overall number of tests may vary by configuration. |
14 |
|
14 |
# First we need to check your environmental variables |
15 |
# Note: The overall number of tests may vary by configuration. |
15 |
for (qw(KOHA_CONF PERL5LIB)) { |
16 |
# First we need to check your environmental variables |
16 |
ok($ret = $ENV{$_}, "ENV{$_} = $ret"); |
17 |
for (qw(KOHA_CONF PERL5LIB)) { |
17 |
} |
18 |
ok( $ret = $ENV{$_}, "ENV{$_} = $ret" ); |
18 |
use_ok('C4::Context'); |
19 |
} |
|
|
20 |
use_ok('C4::Context'); |
19 |
} |
21 |
} |
20 |
|
22 |
|
21 |
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); |
23 |
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); |
Lines 72-119
$module->mock(
Link Here
|
72 |
); |
74 |
); |
73 |
|
75 |
|
74 |
my $history; |
76 |
my $history; |
75 |
$dbh = C4::Context->dbh({ new => 1 }); |
|
|
76 |
|
77 |
|
77 |
$dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ]; |
78 |
my $schema = Koha::Database->new()->schema(); |
78 |
$dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ]; |
79 |
$schema->storage->txn_begin(); |
79 |
$dbh->{mock_add_resultset} = [ ['value'], ['thing3'] ]; |
80 |
$schema->storage->debug(1); |
80 |
$dbh->{mock_add_resultset} = [ ['value'], ['thing4'] ]; |
81 |
my $trace_read; |
|
|
82 |
open my $trace, '>', \$trace_read or die "Can't open variable: $!"; |
83 |
$schema->storage->debugfh( $trace ); |
84 |
|
85 |
C4::Context->set_preference('SillyPreference', 'thing1'); |
86 |
my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference'); |
81 |
|
87 |
|
|
|
88 |
my $pref = C4::Context->preference("SillyPreference"); |
82 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
89 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
83 |
$history = $dbh->{mock_all_history}; |
90 |
ok( $trace_read, 'Retrieved syspref from database'); |
84 |
is(scalar(@{$history}), 1, 'Retrieved syspref from database'); |
91 |
$trace_read = q{}; |
85 |
|
92 |
|
86 |
$dbh->{mock_clear_history} = 1; |
|
|
87 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
93 |
is(C4::Context->preference("SillyPreference"), 'thing1', "Retrieved syspref (value='thing1') successfully with default behavior"); |
88 |
$history = $dbh->{mock_all_history}; |
94 |
is( $trace_read , q{}, 'Did not retrieve syspref from database'); |
89 |
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); |
95 |
$trace_read = q{}; |
90 |
|
96 |
|
91 |
C4::Context->disable_syspref_cache(); |
97 |
C4::Context->disable_syspref_cache(); |
|
|
98 |
$silly_preference->set( { value => 'thing2' } )->store(); |
92 |
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache"); |
99 |
is(C4::Context->preference("SillyPreference"), 'thing2', "Retrieved syspref (value='thing2') successfully with disabled cache"); |
93 |
$history = $dbh->{mock_all_history}; |
100 |
ok($trace_read, 'Retrieved syspref from database'); |
94 |
is(scalar(@{$history}), 1, 'Retrieved syspref from database'); |
101 |
$trace_read = q{}; |
95 |
|
102 |
|
96 |
$dbh->{mock_clear_history} = 1; |
103 |
$silly_preference->set( { value => 'thing3' } )->store(); |
97 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache"); |
104 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully with disabled cache"); |
98 |
$history = $dbh->{mock_all_history}; |
105 |
ok($trace_read, 'Retrieved syspref from database'); |
99 |
is(scalar(@{$history}), 1, 'Retrieved syspref from database'); |
106 |
$trace_read = q{}; |
100 |
|
107 |
|
101 |
C4::Context->enable_syspref_cache(); |
108 |
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"); |
109 |
is(C4::Context->preference("SillyPreference"), 'thing3', "Retrieved syspref (value='thing3') successfully from cache"); |
104 |
$history = $dbh->{mock_all_history}; |
110 |
is( $trace_read, q{}, 'Did not retrieve syspref from database'); |
105 |
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); |
111 |
$trace_read = q{}; |
106 |
|
112 |
|
|
|
113 |
$silly_preference->set( { value => 'thing4' } )->store(); |
107 |
C4::Context->clear_syspref_cache(); |
114 |
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"); |
115 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully after clearing cache"); |
110 |
$history = $dbh->{mock_all_history}; |
116 |
ok($trace_read, 'Retrieved syspref from database'); |
111 |
is(scalar(@{$history}), 1, 'Retrieved syspref from database'); |
117 |
$trace_read = q{}; |
112 |
|
118 |
|
113 |
$dbh->{mock_clear_history} = 1; |
|
|
114 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache"); |
119 |
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache"); |
115 |
$history = $dbh->{mock_all_history}; |
120 |
is( $trace_read, q{}, 'Did not retrieve syspref from database'); |
116 |
is(scalar(@{$history}), 0, 'Did not retrieve syspref from database'); |
121 |
$trace_read = q{}; |
117 |
|
122 |
|
118 |
my $oConnection = C4::Context->Zconn('biblioserver', 0); |
123 |
my $oConnection = C4::Context->Zconn('biblioserver', 0); |
119 |
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous"); |
124 |
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous"); |
120 |
- |
|
|