Debian Codegraph @

lemonldap-ng-common/t/03-Common-Conf-CDBI.t

raw
1 use warnings;
2
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t'
5
6 #########################
7
8 # change 'tests => 1' to 'tests => last_test_to_print';
9
10 use strict;
11 use Test::More tests => 14;
12
13 BEGIN {
14 use_ok('Lemonldap::NG::Common::Conf');
15 }
16
17 #########################
18
19 # Insert your test code below, the Test::More module is use()ed here so read
20 # its man page ( perldoc Test::More ) for help writing this test script.
21
22 my $h;
23 @ARGV = ("help=groups");
24 unlink 't/cdbiConf.sql';
25
26 SKIP: {
27 eval { require DBI; };
28 skip( "DBI not installed", 13 ) if ($@);
29 my $skipSQLite = 0;
30
31 ok(
32 $h = new Lemonldap::NG::Common::Conf( {
33 type => 'CDBI',
34 dbiChain => "DBI:SQLite:dbname=t/cdbiConf.sql",
35 dbiUser => '',
36 dbiPassword => '',
37 }
38 ),
39 'CDBI object'
40 );
41
42 ok( $h->can('_dbh'), 'Driver is build' );
43 eval { require DBD::SQLite };
44 skip( "DBD::SQLite not installed", 11 ) if ($@);
45 ok( $h->_dbh->{sqlite_unicode} = 1, 'Set unicode' );
46 ok(
47 $h->_dbh->do(
48 ' CREATE TABLE lmConfig ( cfgNum int not null primary key, data text)'
49 ),
50 'Test database created'
51 );
52
53 my @test = (
54
55 # simple ascii
56 { cfgNum => 1, test => 'ascii' },
57
58 # utf-8
59 { cfgNum => 2, test => 'Русский' },
60
61 # compatible utf8/latin-1 char but with different codes
62 { cfgNum => 3, test => 'éà' }
63 );
64
65 for ( my $i = 0 ; $i < @test ; $i++ ) {
66 ok( $h->store( $test[$i] ) == $i + 1, "Test $i is stored" )
67 or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
68 my $cfg;
69 ok( $cfg = $h->load( $i + 1 ), "Test $i can be read" )
70 or print STDERR $Lemonldap::NG::Common::Conf::msg;
71 ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" );
72 }
73
74 unlink 't/cdbiConf.sql';
75 }
76