Skip to content

Commit

Permalink
Item14237: Write/Read new style LSC
Browse files Browse the repository at this point in the history
As a measure to make LSC the only source of configuration data for
Foswiki methods writeLSC/readLSC were introduced. They're currently
handling a new LSC format which is not Perl code. But this is not
important as any format could be chosen. What is important is that these
methods deal with writing/reading the low-level config data only. Both
are pluggables to simplify creation of plugins handling special cases of
LSC like use of different backends including remote or database
storages.

- Renamed 'data' parameter to 'dataObj' wherever appropriate; i.e. if
the parameter is a DataHash instance.

- specsMode method can now generate standalone tied data hashes without
touching config's object data attribute.
  • Loading branch information
vrurg committed Apr 21, 2017
1 parent 21a4e8c commit 0ea2eb7
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 54 deletions.
41 changes: 33 additions & 8 deletions UnitTestContrib/test/unit/ConfigTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ sub test_specRegister {
my $holder = $cfg->localize;
$cfg->clear_data;

my $data = $cfg->makeSpecsHash;
my $dataObj = tied %$data;
my $rootSection =
$this->create( 'Foswiki::Config::Section', name => 'Root', );

$cfg->spec(
source => __FILE__,
specs => [
source => __FILE__,
dataObj => $dataObj,
localData => 1,
section => $rootSection,
specs => [
-section => Extensions => [
-text => "Just extensions",
-section => TestExt => [
Expand Down Expand Up @@ -170,10 +178,10 @@ sub test_specRegister {
},
};

$this->assert_deep_equals( $expectedData, $cfg->data,
$this->assert_deep_equals( $expectedData, $data,
"Config structure mismatch with specs definition" );

my $sec = $cfg->rootSection->sections->[0];
my $sec = $rootSection->sections->[0];
$this->assert_equals( "Extensions", $sec->name );
$this->assert_equals( "Just extensions", $sec->getOpt('text') );
$this->assert_equals( "TestExt", $sec->sections->[0]->name );
Expand All @@ -183,12 +191,14 @@ sub test_specRegister {
$this->assert_equals( "Sample extension",
$sec->sections->[1]->getOpt('text') );

my $strKey = $cfg->getKeyNode('Extensions.TestExt.StrKey');
my $strKey =
$dataObj->getKeyObject(qw(Extensions TestExt))->nodes->{StrKey};

$this->assert_equals( "STRING", $strKey->getOpt('type') );
$this->assert_equals( 32, $strKey->getOpt('size') );

my $expertKey = $cfg->getKeyNode('Extensions.SampleExt.Setting');
my $expertKey =
$dataObj->getKeyObject(qw(Extensions SampleExt))->nodes->{Setting};

$this->assert( $expertKey->getOpt('expert'),
"Extensions.SampleExt.Setting must have 'expert' option set" );
Expand All @@ -212,7 +222,7 @@ sub test_specOnLocalData {

$cfg->spec(
source => __FILE__,
data => $dataObj,
dataObj => $dataObj,
section => $section,
specs => [
-section => Section => [
Expand Down Expand Up @@ -577,7 +587,7 @@ sub test_enhanceNonExisting {
# This call must just pass.
$cfg->spec(
source => __FILE__,
data => $dataObj,
dataObj => $dataObj,
section => $section,
specs => [
-section => "Test enhancing" => [
Expand Down Expand Up @@ -698,4 +708,19 @@ qr/Failed to expand string '.*?': key ExpTest.Key1.UndefKey value is undefined/,
};
}

sub test_ReadWriteLSC {
my $this = shift;

$this->app->cfg->data->{ThisKey}{Is}{Not}{From}{Specs} =
"But we will have it in the LSC";

my $lscFile = "./TestLocalSite.cfg";
$this->app->cfg->writeLSC( lscFile => $lscFile, );
my %data;
$this->app->cfg->readLSC( lscFile => $lscFile, data => \%data, );

#unlink $lscFile;
return;
}

1;
Loading

0 comments on commit 0ea2eb7

Please sign in to comment.