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

(-)a/t/Koha/Util/Misc.t (-1 / +68 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 => 4;
21
use Test::Warn;
22
use MARC::Record;
23
use MARC::Field;
24
25
BEGIN {
26
    use_ok( 'Koha::Util::Misc', qw( digest ) );
27
}
28
29
subtest 'pass scalar' => sub {
30
    plan tests => 3;
31
32
    my $str       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit";
33
    my $digest_01 = digest($str);
34
    is( digest($str), $digest_01, 'digest from string OK' );
35
    $str .= '.';
36
    my $digest_02 = digest($str);
37
    isnt( digest($str), $digest_01, 'digest from modified string changed' );
38
    is( digest($str), $digest_02, 'digest from modified string OK' );
39
};
40
41
subtest 'pass hash' => sub {
42
    plan tests => 3;
43
44
    my $data      = { a => 0, b => 7 };
45
    my $digest_01 = digest($data);
46
    is( digest($data), $digest_01, 'digest from hash OK' );
47
    $data->{c} = '11';
48
    my $digest_02 = digest($data);
49
    isnt( digest($data), $digest_01, 'digest from modified hash changed' );
50
    is( digest($data), $digest_02, 'digest from modified hash OK' );
51
};
52
53
subtest 'pass MARC object' => sub {
54
    plan tests => 3;
55
56
    my $rec = MARC::Record->new;
57
    $rec->append_fields( MARC::Field->new( '003', 'DLC' ) );
58
    $rec->append_fields( MARC::Field->new( '245', '0', '0', a => 'Title of a book :' ) );
59
    my $digest_01 = digest($rec);
60
    is( digest($rec), $digest_01, 'digest from MARC object OK' );
61
    $rec->field('245')->update( b => 'subtitle.' );
62
    my $digest_02 = digest($rec);
63
    isnt(
64
        digest($rec), $digest_01,
65
        'digest from modified MARC object changed'
66
    );
67
    is( digest($rec), $digest_02, 'digest from modified MARC object OK' );
68
};

Return to bug 31109