Bug 16044: Add an unsafe flag to Koha::Cache->get_from_cache
[koha-ffzg.git] / t / Cache.t
index 1780025..8adaf1c 100644 (file)
--- a/t/Cache.t
+++ b/t/Cache.t
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 35;
+use Test::More tests => 37;
 
 my $destructorcount = 0;
 
@@ -33,7 +33,7 @@ SKIP: {
     $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
     my $cache = Koha::Cache->get_instance();
 
-    skip "Cache not enabled", 31
+    skip "Cache not enabled", 33
       unless ( $cache->is_cache_active() && defined $cache );
 
     # test fetching an item that isnt in the cache
@@ -181,12 +181,18 @@ SKIP: {
     $item_from_cache = $cache->get_from_cache('test_deep_copy_array');
     @$item_from_cache = qw( another array ref );
     is_deeply( $cache->get_from_cache('test_deep_copy_array'), [ qw ( an array ref ) ], 'An array will be deep copied');
+    $item_from_cache = $cache->get_from_cache('test_deep_copy_array', { unsafe => 1 });
+    @$item_from_cache = qw( another array ref );
+    is_deeply( $cache->get_from_cache('test_deep_copy_array'), [ qw ( another array ref ) ], 'An array will not be deep copied if the unsafe flag is set');
     # Hash
     my %item = ( a => 'hashref' );
     $cache->set_in_cache('test_deep_copy_hash', \%item);
     $item_from_cache = $cache->get_from_cache('test_deep_copy_hash');
     %$item_from_cache = ( another => 'hashref' );
     is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { a => 'hashref' }, 'A hash will be deep copied');
+    $item_from_cache = $cache->get_from_cache('test_deep_copy_hash', { unsafe => 1});
+    %$item_from_cache = ( another => 'hashref' );
+    is_deeply( $cache->get_from_cache('test_deep_copy_hash'), { another => 'hashref' }, 'A hash will not be deep copied if the unsafe flag is set');
 }
 
 END {