Commit f10885c5 authored by Yadd's avatar Yadd
Browse files

Finish #877

parent ba844458
......@@ -69,7 +69,7 @@ sub load {
return 0;
}
$res->{cfgNum} = $cfgNum;
return $self->unserialize($res);
return $res;
}
1;
......
......@@ -2,7 +2,7 @@ package Lemonldap::NG::Common::Conf::Serializer;
use strict;
use utf8;
use Data::Dumper;
use Encode;
use JSON::MaybeXS;
use Lemonldap::NG::Common::Conf::Constants;
......@@ -13,6 +13,7 @@ BEGIN {
*Lemonldap::NG::Common::Conf::unnormalize = \&unnormalize;
*Lemonldap::NG::Common::Conf::serialize = \&serialize;
*Lemonldap::NG::Common::Conf::unserialize = \&unserialize;
*Lemonldap::NG::Common::Conf::oldUnserialize = \&oldUnserialize;
}
## @method string normalize(string value)
......@@ -99,7 +100,7 @@ sub unserialize {
if ($@) {
$Lemonldap::NG::Common::Conf::msg .=
"Unable to decode $k, probably old format. Trying... ($@)";
return oldUnserialize($fields);
return $self->oldUnserialize($fields);
}
}
else {
......@@ -109,8 +110,6 @@ sub unserialize {
}
sub oldUnserialize {
use Carp;
cluck('coucou');
my ( $self, $fields ) = @_;
my $conf;
......
......@@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use strict;
use Test::More;
use Test::More tests => 14;
BEGIN {
use_ok('Lemonldap::NG::Common::Conf');
......@@ -20,22 +20,11 @@ BEGIN {
my $h;
@ARGV = ("help=groups");
unlink 't/lmConf.sql';
my $count = 1;
eval { require DBD::SQLite };
unless ($@) {
use_ok('DBI');
my $dbh = DBI->connect( "dbi:SQLite:dbname=t/lmConf.sql",
'', '', { AutoCommit => 1 } );
$dbh->{sqlite_unicode} = 1;
ok(
$dbh->do(
' CREATE TABLE lmConfig ( cfgNum int not null primary key, data text)'
),
'Test database created'
);
undef $dbh;
$count += 2;
SKIP: {
eval { require DBI; };
skip( "DBI not installed", 13 ) if ($@);
my $skipSQLite = 0;
ok(
$h = new Lemonldap::NG::Common::Conf(
......@@ -50,8 +39,15 @@ unless ($@) {
);
ok( $h->can('_dbh'), 'Driver is build' );
$count += 2;
eval { require DBD::SQLite };
skip( "DBD::SQLite not installed", 11 ) if ($@);
ok( $h->_dbh->{sqlite_unicode} = 1, 'Set unicode' );
ok(
$h->_dbh->do(
' CREATE TABLE lmConfig ( cfgNum int not null primary key, data text)'
),
'Test database created'
);
my @test = (
......@@ -68,16 +64,12 @@ unless ($@) {
for ( my $i = 0 ; $i < @test ; $i++ ) {
ok( $h->store( $test[$i] ) == $i + 1, "Test $i is stored" )
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
$count++;
my $cfg;
ok( $cfg = $h->load( $i + 1 ), "Test $i can be read" )
or print STDERR $Lemonldap::NG::Common::Conf::msg;
ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" );
$count += 2;
}
}
unlink 't/lmConf.sql';
done_testing($count);
unlink 't/lmConf.sql';
}
......@@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use strict;
use Test::More;
use Test::More tests => 14;
BEGIN {
use_ok('Lemonldap::NG::Common::Conf');
......@@ -20,22 +20,11 @@ BEGIN {
my $h;
@ARGV = ("help=groups");
unlink 't/lmConf.sql';
my $count = 1;
eval { require DBD::SQLite };
unless ($@) {
use_ok('DBI');
my $dbh = DBI->connect( "dbi:SQLite:dbname=t/lmConf.sql",
'', '', { AutoCommit => 1 } );
$dbh->{sqlite_unicode} = 1;
ok(
$dbh->do(
" CREATE TABLE lmConfig ( cfgNum int not null, field varchar(255) NOT NULL DEFAULT '', value longblob, PRIMARY KEY (cfgNum,field))"
),
'Test database created'
);
undef $dbh;
$count += 2;
SKIP: {
eval { require DBI; };
skip( "DBI not installed", 13 ) if ($@);
my $skipSQLite = 0;
ok(
$h = new Lemonldap::NG::Common::Conf(
......@@ -50,8 +39,16 @@ unless ($@) {
);
ok( $h->can('_dbh'), 'Driver is build' );
eval { require DBD::SQLite };
skip( "DBD::SQLite not installed", 11 ) if ($@);
ok( $h->_dbh->{sqlite_unicode} = 1, 'Set unicode' );
ok(
$h->_dbh->do(
"CREATE TABLE lmConfig ( cfgNum int not null, field varchar(255) NOT NULL DEFAULT '', value longblob, PRIMARY KEY (cfgNum,field))"
$count += 2;
),
'Test database created'
);
my @test = (
......@@ -68,16 +65,12 @@ unless ($@) {
for ( my $i = 0 ; $i < @test ; $i++ ) {
ok( $h->store( $test[$i] ) == $i + 1, "Test $i is stored" )
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
$count++;
my $cfg;
ok( $cfg = $h->load( $i + 1 ), "Test $i can be read" )
or print STDERR $Lemonldap::NG::Common::Conf::msg;
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!$@";
ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" );
$count += 2;
}
}
unlink 't/lmConf.sql';
done_testing($count);
unlink 't/lmConf.sql';
}
......@@ -36,19 +36,9 @@ registerDB = Null
$ini->flush();
open( CONF, ">$dir/lmConf-1" ) or die $@;
open( CONF, ">$dir/lmConf-1.js" ) or die $@;
print CONF "
cfgNum
1
useXForwardedForIP
0
key
tmp
";
print CONF '{"cfgNum":1,"useXForwardedForIP":0,"key":"tmp"}';
CONF->flush();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment