Lines 1-14
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
2 |
|
3 |
# This Koha test module is a stub! |
3 |
# Tests Koha::Cache and Koha::Cache::Memcached (through Koha::Cache) |
4 |
# Add more tests here!!! |
|
|
5 |
|
4 |
|
6 |
use strict; |
5 |
use strict; |
7 |
use warnings; |
6 |
use warnings; |
8 |
|
7 |
|
9 |
use Test::More tests => 1; |
8 |
use Test::More tests => 9; |
10 |
|
9 |
|
11 |
BEGIN { |
10 |
BEGIN { |
12 |
use_ok('Koha::Cache'); |
11 |
use_ok('Koha::Cache'); |
|
|
12 |
use_ok('C4::Context'); |
13 |
} |
13 |
} |
14 |
|
14 |
|
15 |
- |
15 |
SKIP: { |
|
|
16 |
skip "Memcached not enabled", 7 unless C4::Context->ismemcached; |
17 |
|
18 |
my $cache = Koha::Cache->new ( { 'cache_servers' => $ENV{'MEMCACHED_SERVERS'} } ); |
19 |
|
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"); |
22 |
|
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"); |
27 |
|
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"); |
32 |
|
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)"); |
37 |
|
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"); |
43 |
} |