Koha/t/db_dependent/sysprefs.t
Jonathan Druart 9820f9dfbd Bug 11998: Use Koha::Cache to cache sysprefs
At the moment, the sysprefs are only cache in the thread memory
executing the processus
When using Plack, that means we need to clear the syspref cache on each
page.
To avoid that, we can use Koha::Cache to cache the sysprefs correctly.

A big part of the authorship of this patch goes to Robin Sheat.

Test plan:
1/ Add/Update/Delete local use prefs
2/ Update pref values and confirm that the changes are correctly taken
into account

Signed-off-by: Chris <chrisc@catalyst.net.nz>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Tested with plack with syspref cache enabled, there is some time between setting the syspref and applying it, but it takes just one reload of page, it shouldn't be problem, should it?
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>

Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl>
Tested with CGI and CGI + memcache; some small issues still remain,
but it would be better to deal with them in separate bug reports
if necessary

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
2016-03-15 07:08:28 +00:00

63 lines
2.4 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha.
#
# Copyright (C) 2012 BibLibre SARL
# Copyright (C) 2013 Equinox Software, Inc.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 8;
use C4::Context;
# Start transaction
my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 1;
$dbh->{AutoCommit} = 0;
my $opacheader = C4::Context->preference('opacheader');
my $newopacheader = "newopacheader";
C4::Context->set_preference( 'OPACHEADER', $newopacheader );
is( C4::Context->preference('opacheader'), $newopacheader, 'The pref should have been set correctly' );
C4::Context->set_preference( 'opacheader', $opacheader );
is( C4::Context->preference('OPACHEADER'), $opacheader, 'A pref name should be case insensitive');
$ENV{OVERRIDE_SYSPREF_opacheader} = 'this is an override';
C4::Context->clear_syspref_cache();
is(
C4::Context->preference('opacheader'),
'this is an override',
'system preference value overridden from environment'
);
is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system preference should return undef');
C4::Context->set_preference( 'IDoNotExist', 'NonExistent' );
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' );
C4::Context->set_preference('testpreference', 'abc');
C4::Context->delete_preference('testpreference');
is(C4::Context->preference('testpreference'), undef, 'deleting preferences');
C4::Context->set_preference('testpreference', 'def');
# Delete from the database, it should still be in cache
$dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'");
is(C4::Context->preference('testpreference'), 'def', 'caching preferences');
C4::Context->clear_syspref_cache();
is(C4::Context->preference('testpreference'), undef, 'clearing preference cache');
$dbh->rollback;