From 34be102c8d31e6d543729c88a820450a0867d1f7 Mon Sep 17 00:00:00 2001 From: Chris Hall Date: Tue, 22 Nov 2011 08:55:19 +1300 Subject: [PATCH] [SIGNED-OFF] Unit test for Koha/Cache.pm (which includes Koha/Cache/Memcahed.pm) http://bugs.koha-community.org/show_bug.cgi?id=7248 Signed-off-by: Katrin Fischer perl t/Cache.t completes successfully. 1..9 ok 1 - use Koha::Cache; ok 2 - use C4::Context; ok 3 - fetching item NOT in cache ok 4 - fetching expired item from cache ok 5 - fetching valid item from cache ok 6 - fetching cleared item from cache ok 7 - fetching valid item from cache (after clearing another item) ok 8 - fetching flushed item from cache ok 9 - fetching flushed item from cache --- t/Cache.t | 35 ++++++++++++++++++++++++++++++----- 1 files changed, 30 insertions(+), 5 deletions(-) diff --git a/t/Cache.t b/t/Cache.t index 75f5acf..a75ef52 100644 --- a/t/Cache.t +++ b/t/Cache.t @@ -1,14 +1,39 @@ #!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! + +# Tests Koha::Cache and Koha::Cache::Memcached (through Koha::Cache) use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 9; BEGIN { - use_ok('C4::Cache'); + use_ok('Koha::Cache'); + use_ok('C4::Context'); } +my $cache = Koha::Cache->new ( { 'cache_servers' => C4::Context->config('memcached_servers') } ); + +# test fetching an item that isnt in the cache +is( $cache->get_from_cache("not in here"), undef, "fetching item NOT in cache"); + +# test expiry time in cache +$cache->set_in_cache("timeout", "I AM DATA", 1); # expiry time of 1 second +sleep 1; +is( $cache->get_from_cache("timeout"), undef, "fetching expired item from cache"); + +# test fetching a valid, non expired, item from cache +$cache->set_in_cache("clear_me", "I AM MORE DATA", 1000); # overly large expiry time, clear below +$cache->set_in_cache("dont_clear_me", "I AM MORE DATA22", 1000); # overly large expiry time, clear below +is( $cache->get_from_cache("clear_me"), "I AM MORE DATA", "fetching valid item from cache"); + +# test clearing from cache +$cache->clear_from_cache("clear_me"); +is( $cache->get_from_cache("clear_me"), undef, "fetching cleared item from cache"); +is( $cache->get_from_cache("dont_clear_me"), "I AM MORE DATA22", "fetching valid item from cache (after clearing another item)"); + +#test flushing from cache +$cache->set_in_cache("flush_me", "testing 1 data"); +$cache->flush_all; +is( $cache->get_from_cache("flush_me"), undef, "fetching flushed item from cache"); +is( $cache->get_from_cache("dont_clear_me"), undef, "fetching flushed item from cache"); -- 1.7.5.4