02-Common-Conf-File.t 1.73 KB
Newer Older
1 2 3 4 5 6 7
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

8 9
use strict;
use Test::More;
10
BEGIN { use_ok('Lemonldap::NG::Common::Conf') }
11 12 13 14 15 16

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

17
my $h;
18

19 20
ok( $h = new Lemonldap::NG::Common::Conf(
        {   type    => 'File',
21
            dirName => "t/",
Xavier Guimard's avatar
Xavier Guimard committed
22
        }
23 24
    ),
    'type => file',
25
);
26
my $count = 2;
27

28 29 30 31 32 33 34 35 36 37 38 39
my @test = (

    #  simple ascii
    { cfgNum => 1, test => 'ascii' },

    #  utf-8
    { cfgNum => 1, test => 'Русский' },

    #  compatible utf8/latin-1 char but with different codes
    { cfgNum => 1, test => 'éà' }
);

40
for ( my $i = 0; $i < @test; $i++ ) {
41
    ok( $h->store( $test[$i] ) == 1, "Test $i is stored" )
42
        or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
43 44 45
    $count++;
    if ( -x '/usr/bin/file' ) {
        eval {
46
            open F, 'file t/lmConf-1.json |';
47 48
            $_ = join( '', <F> );
            close F;
49 50 51 52

            ## Debian Buster 'file' command returns JSON DATA
            ok( /(ascii|utf-?8|json\sdata)/si, "File is $1 encoded" )
                or print STDERR "Result: $_\n";
53 54 55 56 57
            $count++;
        };
    }
    my $cfg;
    ok( $cfg = $h->load(1), "Test $i can be read" )
58
        or print STDERR $Lemonldap::NG::Common::Conf::msg;
59
    ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" )
60
        or print STDERR "Expect $cfg->{test} eq $test[$i]->{test}\n";
61 62 63
    $count += 2;
}

64
unlink 't/lmConf-1.json';
65 66

done_testing($count);