| 1 |
# Check that HTML forms exists for all types of parameter and that no HTML |
| 2 |
# forms are unused |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
use Data::Dumper; |
| 6 |
use strict; |
| 7 |
use warnings; |
| 8 |
|
| 9 |
my $formDir = 'site/htdocs/static/forms'; |
| 10 |
|
| 11 |
my $count = 0; |
| 12 |
use_ok('Lemonldap::NG::Manager::Build::Tree'); |
| 13 |
use_ok('Lemonldap::NG::Manager::Build::CTrees'); |
| 14 |
use_ok('Lemonldap::NG::Manager::Build::Attributes'); |
| 15 |
$count += 3; |
| 16 |
|
| 17 |
ok( opendir( D, $formDir ), 'Found forms dir' ); |
| 18 |
my %forms = map { s/\.html$// ? ( $_ => 1 ) : () } readdir D; |
| 19 |
close D; |
| 20 |
|
| 21 |
delete $forms{white}; |
| 22 |
delete $forms{mini}; |
| 23 |
delete $forms{restore}; |
| 24 |
|
| 25 |
my ( @types, $attr, $tree, $ctrees ); |
| 26 |
ok( $tree = Lemonldap::NG::Manager::Build::Tree::tree(), 'Get tree' ); |
| 27 |
ok( $ctrees = Lemonldap::NG::Manager::Build::CTrees::cTrees(), 'Get cTrees' ); |
| 28 |
ok( $attr = Lemonldap::NG::Manager::Build::Attributes::attributes(), |
| 29 |
'Get attributes' ); |
| 30 |
$count += 4; |
| 31 |
|
| 32 |
my %types = %{ getTypes( $tree, values(%$ctrees), $attr ) }; |
| 33 |
|
| 34 |
foreach (qw(home homeViewer menuCat menuApp authParamsTextContainer)) { |
| 35 |
ok( $forms{$_}, "Found $_ form" ); |
| 36 |
$count++; |
| 37 |
delete $forms{$_}; |
| 38 |
} |
| 39 |
|
| 40 |
foreach my $type ( keys %types ) { |
| 41 |
delete $types{$type}; |
| 42 |
if ( $type =~ |
| 43 |
/^(?:array|authParamsText|url|PerlModule|hostname|pcre|lmAttrOrMacro|subContainer|(?:EcOr)?RSAP(?:ublic|rivate)Key(?:OrCertificate)?)$/ |
| 44 |
) |
| 45 |
{ |
| 46 |
delete $forms{$type}; |
| 47 |
next; |
| 48 |
} |
| 49 |
ok( $forms{$type}, "Found $type" ); |
| 50 |
delete $forms{$type}; |
| 51 |
$count++; |
| 52 |
if ( $type =~ s/Container$// ) { |
| 53 |
next if ( $type eq 'simpleInput' ); |
| 54 |
ok( $forms{$type}, "Found $type" ); |
| 55 |
delete $forms{$type}; |
| 56 |
$count++; |
| 57 |
} |
| 58 |
} |
| 59 |
ok( !%forms, "No unused forms" ) or print STDERR "Found:\n" . Dumper( \%forms ); |
| 60 |
$count++; |
| 61 |
|
| 62 |
done_testing($count); |
| 63 |
|
| 64 |
sub getTypes { |
| 65 |
my @trees = @_; |
| 66 |
my $res = { 'text' => 1 }; |
| 67 |
foreach my $t (@trees) { |
| 68 |
if ( ref($t) eq 'HASH' ) { |
| 69 |
foreach my $a ( values %$t ) { |
| 70 |
|
| 71 |
my $tmp = $a->{type}; |
| 72 |
$res->{$tmp}++ if ($tmp); |
| 73 |
} |
| 74 |
} |
| 75 |
else { |
| 76 |
_getTypes( $t, $res ); |
| 77 |
} |
| 78 |
} |
| 79 |
return $res; |
| 80 |
} |
| 81 |
|
| 82 |
sub _getTypes { |
| 83 |
my ( $tree, $res ) = splice @_; |
| 84 |
$tree = [$tree] unless ( ref($tree) ); |
| 85 |
foreach my $k (@$tree) { |
| 86 |
if ( ref($k) ) { |
| 87 |
_getTypes( $k->{nodes}, $res ) if ( $k->{nodes} ); |
| 88 |
_getTypes( $k->{nodes_cond}, $res ) if ( $k->{nodes_cond} ); |
| 89 |
$res->{ $k->{form} }++ if ( $k->{form} ); |
| 90 |
} |
| 91 |
} |
| 92 |
} |