Skip to content

Commit

Permalink
Item12888: unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford committed Oct 26, 2014
1 parent ff7892f commit a2559f9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
19 changes: 15 additions & 4 deletions ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ each being a hash with keys =level= (e.g. =warnings=, =errors=), and
Any errors will be reported using exceptions.
*NOTE* check_dependencies will look into the values of other keys for
$Foswiki::cfg references, for example into the entries in a PERL hash.
If a dependency is found, the closest checkable entity (i.e. the PERL
key) will be checked, and *not* the subkey.
=cut

sub _getSetParams {
Expand Down Expand Up @@ -515,7 +520,7 @@ sub check_current_value {
# Reload Foswiki::cfg without expansions so we can find
# dependencies
local %Foswiki::cfg = ();
Foswiki::Configure::Load::readConfig( 1, 1 );
Foswiki::Configure::Load::readConfig( 1, 0, 1 );
if ( $params->{with} ) {
while ( my ( $k, $v ) = each %{ $params->{with} } ) {
eval "\$Foswiki::cfg$k=$v";
Expand All @@ -529,13 +534,19 @@ sub check_current_value {
my %done;
while ( my $dep = shift @dep_keys ) {
next if $done{$dep};
$check{$dep} = 1;
$done{$dep} = 1;
$done{$dep} = 1;

# Find the closest enclosing key that has a spec (we only
# check things with specs) and add it to the check set
my $cd = $dep;
while ( $cd && !$root->getValueObject($cd) ) {
$cd =~ s/(.*){.*?}$/$1/;
}
$check{$cd} = 1 if $cd;
push( @dep_keys, @{ $deps{forward}->{$dep} } )
if $deps{forward}->{$dep};
}
}

foreach my $k ( keys %check ) {
next unless $k;
my $spec = $root->getValueObject($k);
Expand Down
11 changes: 9 additions & 2 deletions ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin/Config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{EXPERT} = 'EXPERT';
# Should be 'empty'
# $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{empty} = 'empty';
# **STRING**
# Should be a list of other items
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{DEPENDS} = '$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H} and $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{EXPERT} ans $$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{NotPresent}';
# Should contain other items
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{DEP_STRING} = 'xxx$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H}xxx';
# **PERL**
# Should contain other items
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{DEP_PERL} = {
'string' => 'xxx$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H}xxx',
'hash' => { 'hash' => 'xxx$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H}xxx' },
'array' => [ '$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H}' ]
};


32 changes: 15 additions & 17 deletions ConfigurePlugin/test/unit/ConfigurePlugin/ConfigurePluginTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,19 @@ sub test_getspec {
$this->assert_str_equals( 'STRING', $spec->{default} );
$this->assert_str_equals( '{Plugins}{ConfigurePlugin}{Test}{STRING}',
$spec->{keys} );
$this->assert_str_equals( 'STRING', $spec->{current_value} );
$this->assert_matches( qr/^When you press the.*of report.$/s,
$spec->{desc} );
$this->assert_matches( qr/^When you press.*of report.$/s, $spec->{desc} );
$this->assert_num_equals( 4, $spec->{depth} );
$this->assert_num_equals( 2, scalar @{ $spec->{defined_at} } );
$this->assert_num_equals( 2, scalar @{ $spec->{FEEDBACK} } );
my $fb = $spec->{FEEDBACK}->[0];
$this->assert( $fb->{auth} );
$this->assert_str_equals( 'Test', $fb->{wizard} );
$this->assert_str_equals( 'test', $fb->{method} );
$this->assert_str_equals( 'test1', $fb->{method} );
$this->assert_str_equals( 'Test one', $fb->{label} );
$fb = $spec->{FEEDBACK}->[1];
$this->assert( !$fb->{auth} );
$this->assert_str_equals( 'Gandalf', $fb->{wizard} );
$this->assert_str_equals( 'wand', $fb->{method} );
$this->assert_str_equals( 'Test', $fb->{wizard} );
$this->assert_str_equals( 'test1', $fb->{method} );
$this->assert_str_equals( 'Test two', $fb->{label} );

my $ch = $spec->{CHECK};
Expand Down Expand Up @@ -251,18 +249,18 @@ sub test_check_dependencies {
};
my $report =
Foswiki::Plugins::ConfigurePlugin::check_current_value($params);
$this->assert_num_equals( 2, scalar @$report );
my ( $first, $second );
if ( $report->[0]->{keys} =~ /DEPENDS/ ) {
( $first, $second ) = ( $report->[0], $report->[1] );
}
else {
( $first, $second ) = ( $report->[1], $report->[0] );
}
$this->assert_str_equals( '{Plugins}{ConfigurePlugin}{Test}{DEPENDS}',
$first->{keys} );
$this->assert_num_equals(
3,
scalar @$report,
Data::Dumper->Dump( [$report] )
);
my @r = sort { $a->{keys} cmp $b->{keys} } @$report;
$this->assert_str_equals( '{Plugins}{ConfigurePlugin}{Test}{DEP_PERL}',
$r[0]->{keys} );
$this->assert_str_equals( '{Plugins}{ConfigurePlugin}{Test}{DEP_STRING}',
$r[1]->{keys} );
$this->assert_str_equals( '{Plugins}{ConfigurePlugin}{Test}{H}',
$second->{keys} );
$r[2]->{keys} );
}

1;
Expand Down

0 comments on commit a2559f9

Please sign in to comment.