From 019f16a401bb9f30b4ffed16805ee449806bd481 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 3 Jun 2024 13:42:29 +0000 Subject: [PATCH] Bug 31109: Unit tests for Koha::Util::Misc::digest --- t/Koha/Util/Misc.t | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 t/Koha/Util/Misc.t diff --git a/t/Koha/Util/Misc.t b/t/Koha/Util/Misc.t new file mode 100755 index 0000000000..c313d29ed9 --- /dev/null +++ b/t/Koha/Util/Misc.t @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 4; +use Test::Warn; +use MARC::Record; +use MARC::Field; + +BEGIN { + use_ok( 'Koha::Util::Misc', qw( digest ) ); +} + +subtest 'pass scalar' => sub { + plan tests => 3; + + my $str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"; + my $digest_01 = digest($str); + is( digest($str), $digest_01, 'digest from string OK' ); + $str .= '.'; + my $digest_02 = digest($str); + isnt( digest($str), $digest_01, 'digest from modified string changed' ); + is( digest($str), $digest_02, 'digest from modified string OK' ); +}; + +subtest 'pass hash' => sub { + plan tests => 3; + + my $data = { a => 0, b => 7 }; + my $digest_01 = digest($data); + is( digest($data), $digest_01, 'digest from hash OK' ); + $data->{c} = '11'; + my $digest_02 = digest($data); + isnt( digest($data), $digest_01, 'digest from modified hash changed' ); + is( digest($data), $digest_02, 'digest from modified hash OK' ); +}; + +subtest 'pass MARC object' => sub { + plan tests => 3; + + my $rec = MARC::Record->new; + $rec->append_fields( MARC::Field->new( '003', 'DLC' ) ); + $rec->append_fields( MARC::Field->new( '245', '0', '0', a => 'Title of a book :' ) ); + my $digest_01 = digest($rec); + is( digest($rec), $digest_01, 'digest from MARC object OK' ); + $rec->field('245')->update( b => 'subtitle.' ); + my $digest_02 = digest($rec); + isnt( + digest($rec), $digest_01, + 'digest from modified MARC object changed' + ); + is( digest($rec), $digest_02, 'digest from modified MARC object OK' ); +}; -- 2.39.2