View | Details | Raw Unified | Return to bug 31109
Collapse All | Expand All

(-)a/t/Koha/Util/Misc.t (-1 / +65 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
use Test::Warn;
22
use MARC::Record;
23
use MARC::Field;
24
use Koha::Util::Misc;
25
26
subtest 'pass scalar' => sub {
27
    plan tests => 3;
28
29
    my $str       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit";
30
    my $digest_01 = Koha::Util::Misc::digest($str);
31
    is( Koha::Util::Misc::digest($str), $digest_01, 'digest from string OK' );
32
    $str .= '.';
33
    my $digest_02 = Koha::Util::Misc::digest($str);
34
    isnt( Koha::Util::Misc::digest($str), $digest_01, 'digest from modified string changed' );
35
    is( Koha::Util::Misc::digest($str), $digest_02, 'digest from modified string OK' );
36
};
37
38
subtest 'pass hash' => sub {
39
    plan tests => 3;
40
41
    my $data      = { a => 0, b => 7 };
42
    my $digest_01 = Koha::Util::Misc::digest($data);
43
    is( Koha::Util::Misc::digest($data), $digest_01, 'digest from hash OK' );
44
    $data->{c} = '11';
45
    my $digest_02 = Koha::Util::Misc::digest($data);
46
    isnt( Koha::Util::Misc::digest($data), $digest_01, 'digest from modified hash changed' );
47
    is( Koha::Util::Misc::digest($data), $digest_02, 'digest from modified hash OK' );
48
};
49
50
subtest 'pass MARC object' => sub {
51
    plan tests => 3;
52
53
    my $rec = MARC::Record->new;
54
    $rec->append_fields( MARC::Field->new( '003', 'DLC' ) );
55
    $rec->append_fields( MARC::Field->new( '245', '0', '0', a => 'Title of a book :' ) );
56
    my $digest_01 = Koha::Util::Misc::digest($rec);
57
    is( Koha::Util::Misc::digest($rec), $digest_01, 'digest from MARC object OK' );
58
    $rec->field('245')->update( b => 'subtitle.' );
59
    my $digest_02 = Koha::Util::Misc::digest($rec);
60
    isnt(
61
        Koha::Util::Misc::digest($rec), $digest_01,
62
        'digest from modified MARC object changed'
63
    );
64
    is( Koha::Util::Misc::digest($rec), $digest_02, 'digest from modified MARC object OK' );
65
};

Return to bug 31109