Skip to content

Commit

Permalink
Item14237: First parsing of basic specs structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Dec 3, 2016
1 parent cbaaf0b commit 88d43c7
Show file tree
Hide file tree
Showing 8 changed files with 1,097 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test/unit/AdminOnlyAccessControlTests.pm 0644
test/unit/AttrsTests.pm 0644
test/unit/CacheTests.pm 0644
test/unit/ClientTests.pm 0644
test/unit/ConfigTests.pm 0644
test/unit/ConfigureQueryTests.pm 0644
test/unit/ConfigureSaveTests.pm 0644
test/unit/ConfigureTestCase.pm 0644
Expand Down
1 change: 1 addition & 0 deletions UnitTestContrib/lib/Unit/TestApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ respective callbacks. Each handler =data= parameter is a hash whith the only
key =app= containing reference to the application object.
=cut

has callbacks => (
is => 'rw',
lazy => 1,
Expand Down
135 changes: 135 additions & 0 deletions UnitTestContrib/test/unit/ConfigTests.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package ConfigTests;
use v5.14;

use Foswiki;
use Try::Tiny;

use Foswiki::Class;
extends qw( FoswikiTestCase );

around set_up => sub {
my $orig = shift;
my $this = shift;

$orig->( $this, @_ );

# You can now safely modify $Foswiki::cfg

try {
$this->createNewFoswikiApp(
requestParams => { initializer => '', },
engineParams =>
{ initialAttributes => { path_info => '/TestCases/WebHome', }, },
user => 'AdminUser',
);
}
catch {
my $e = Foswiki::Exception::Fatal->transmute( $_, 0 );
if ( $e->isa('Foswiki::AccessControlException') ) {
$this->assert( 0, $e->stringify );
}
else {
$e->rethrow;
}
};

my $cfgData = $this->app->cfg->data;
$cfgData->{ConfigTests}{SubKey1}{Key1} = "This is key 1";
$cfgData->{ConfigTests}{SubKey1}{Key2} = "This is key 2";
$cfgData->{ConfigTests}{SubKey1}{Key3} = [qw(This is key 3)];
$cfgData->{ConfigTests}{SubKey2}{HashKey} = {
a => 3,
b => 2,
c => 1,
};

return;
};

around tear_down => sub {
my $orig = shift;
my $this = shift;

# Always do this, and always do it last
$orig->($this);

return;
};

sub test_getNode {
my $this = shift;

$this->app->cfg->tieData;

my $node = $this->app->cfg->getKeyNode('ConfigTests.SubKey1.Key2');

$this->assert_equals( "This is key 2", $node->value );

return;
}

sub test_TieUntie {
my $this = shift;

$this->app->cfg->tieData;
$this->app->cfg->untieData;

my $cfgData = $this->app->cfg->data;
$this->assert( !tied %$cfgData, "Config data must not be tied." );
$this->assert(
!tied %{ $cfgData->{ConfigTests} },
"First level LSC keys must not be tied"
);
$this->assert(
!tied %{ $cfgData->{ConfigTests}{SubKey1} },
"Second level LSC keys must not be tied"
);
}

sub test_specSimple {
my $this = shift;

$this->app->cfg->spec(
__FILE__,
-section => Extensions => -text => "Just extensions" => [
-section => TestExt => -text => "Test extension" => [
-modprefix => 'Foswiki::Extension::TestExt',
'ANewKey.NewSubKey' => [
Valid => { -type => 'BOOL', },
Text => { -type => 'TEXT', },
],
'Extensions.TestExt' => {
Sample => { -type => 'INTEGER', },
StrKey => { -type => 'TEXT(32)', }
},
],
-section => SampleExt => -text => "Sample extension" => [
-modprefix => 'Foswiki::Extension::SampleExt',
'Extensions.SampleExt' => [
Option => {
-type => 'BOOL',
-default => 0,
},
Setting => {
-type => 'SELECT',
-variants => [qw(one two three)],
}
],
-modprefix => 'Foswiki::Extension::OtherExt',
'Extensions.SampleExt' => [
Param => {
-type => 'NUMBER',
-default => 3.14,
},
OneOf => {
-type => 'PERL',
-default => { a => 1, b => 2, c => 3, },
-expert => 1,
},
],
],
],
);
}

1;
Loading

0 comments on commit 88d43c7

Please sign in to comment.