From 0f082e6583aba50835c1c688599d510e117b2f20 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Mar 2016 15:50:15 +0000 Subject: [PATCH] Bug 16044: Add tests to make sure structures will be copied Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Brendan A Gallagher (cherry picked from commit 3bfe541d0d97cdad08f9be2cff20c04a03424a25) Signed-off-by: Julian Maurice --- t/Cache.t | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/t/Cache.t b/t/Cache.t index 0548a6202c..1780025667 100644 --- 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 { -- 2.11.4.GIT