add edit_quotes to es-ES/mandatory/userpermissions.sql
[koha.git] / t / Cache.t
blob286c0c9c9227737e44284f23234c4f9ef6edd58a
1 #!/usr/bin/perl
3 # Tests Koha::Cache and Koha::Cache::Memcached (through Koha::Cache)
5 use strict;
6 use warnings;
8 use Test::More tests => 9;
10 BEGIN {
11 use_ok('Koha::Cache');
12 use_ok('C4::Context');
15 SKIP: {
16 skip "Memcached not enabled", 7 unless C4::Context->ismemcached;
18 my $cache = Koha::Cache->new ( { 'cache_servers' => $ENV{'MEMCACHED_SERVERS'} } );
20 # test fetching an item that isnt in the cache
21 is( $cache->get_from_cache("not in here"), undef, "fetching item NOT in cache");
23 # test expiry time in cache
24 $cache->set_in_cache("timeout", "I AM DATA", 1); # expiry time of 1 second
25 sleep 1;
26 is( $cache->get_from_cache("timeout"), undef, "fetching expired item from cache");
28 # test fetching a valid, non expired, item from cache
29 $cache->set_in_cache("clear_me", "I AM MORE DATA", 1000); # overly large expiry time, clear below
30 $cache->set_in_cache("dont_clear_me", "I AM MORE DATA22", 1000); # overly large expiry time, clear below
31 is( $cache->get_from_cache("clear_me"), "I AM MORE DATA", "fetching valid item from cache");
33 # test clearing from cache
34 $cache->clear_from_cache("clear_me");
35 is( $cache->get_from_cache("clear_me"), undef, "fetching cleared item from cache");
36 is( $cache->get_from_cache("dont_clear_me"), "I AM MORE DATA22", "fetching valid item from cache (after clearing another item)");
38 #test flushing from cache
39 $cache->set_in_cache("flush_me", "testing 1 data");
40 $cache->flush_all;
41 is( $cache->get_from_cache("flush_me"), undef, "fetching flushed item from cache");
42 is( $cache->get_from_cache("dont_clear_me"), undef, "fetching flushed item from cache");