|
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 |
my $cache = Koha::Cache->new ( { 'cache_servers' => C4::Context->config('memcached_servers') } ); |
|
|
16 |
|
| 17 |
# test fetching an item that isnt in the cache |
| 18 |
is( $cache->get_from_cache("not in here"), undef, "fetching item NOT in cache"); |
| 19 |
|
| 20 |
# test expiry time in cache |
| 21 |
$cache->set_in_cache("timeout", "I AM DATA", 1); # expiry time of 1 second |
| 22 |
sleep 1; |
| 23 |
is( $cache->get_from_cache("timeout"), undef, "fetching expired item from cache"); |
| 24 |
|
| 25 |
# test fetching a valid, non expired, item from cache |
| 26 |
$cache->set_in_cache("clear_me", "I AM MORE DATA", 1000); # overly large expiry time, clear below |
| 27 |
$cache->set_in_cache("dont_clear_me", "I AM MORE DATA22", 1000); # overly large expiry time, clear below |
| 28 |
is( $cache->get_from_cache("clear_me"), "I AM MORE DATA", "fetching valid item from cache"); |
| 29 |
|
| 30 |
# test clearing from cache |
| 31 |
$cache->clear_from_cache("clear_me"); |
| 32 |
is( $cache->get_from_cache("clear_me"), undef, "fetching cleared item from cache"); |
| 33 |
is( $cache->get_from_cache("dont_clear_me"), "I AM MORE DATA22", "fetching valid item from cache (after clearing another item)"); |
| 34 |
|
| 35 |
#test flushing from cache |
| 36 |
$cache->set_in_cache("flush_me", "testing 1 data"); |
| 37 |
$cache->flush_all; |
| 38 |
is( $cache->get_from_cache("flush_me"), undef, "fetching flushed item from cache"); |
| 39 |
is( $cache->get_from_cache("dont_clear_me"), undef, "fetching flushed item from cache"); |