Bug 16044: Add tests to make sure structures will be copied
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 15 Mar 2016 15:50:15 +0000 (15:50 +0000)
committerJulian Maurice <julian.maurice@biblibre.com>
Thu, 16 Jun 2016 11:44:38 +0000 (13:44 +0200)
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
(cherry picked from commit 3bfe541d0d97cdad08f9be2cff20c04a03424a25)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

t/Cache.t

index 0548a62..1780025 100644 (file)
--- a/t/Cache.t
+++ b/t/Cache.t
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 32;
+use Test::More tests => 35;
 
 my $destructorcount = 0;
 
@@ -33,7 +33,7 @@ SKIP: {
     $ENV{ MEMCACHED_NAMESPACE } = 'unit_tests';
     my $cache = Koha::Cache->get_instance();
 
-    skip "Cache not enabled", 28
+    skip "Cache not enabled", 31
       unless ( $cache->is_cache_active() && defined $cache );
 
     # test fetching an item that isnt in the cache
@@ -167,6 +167,26 @@ SKIP: {
     is(length($utf8_res), 1, 'UTF8 string length correct');
     # ...and that it's really the character we intend
     is(ord($utf8_res), 8364, 'UTF8 string value correct');
+
+    # Make sure the item will be deep copied
+    # Scalar
+    my $item = "just a simple scalar";
+    $cache->set_in_cache('test_deep_copy', $item);
+    my $item_from_cache = $cache->get_from_cache('test_deep_copy');
+    $item_from_cache = "a modified scalar";
+    is( $cache->get_from_cache('test_deep_copy'), 'just a simple scalar', 'A scalar will not be modified in the cache if get from the cache' );
+    # Array
+    my @item = qw( an array ref );
+    $cache->set_in_cache('test_deep_copy_array', \@item);
+    $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');
+    # 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');
 }
 
 END {