Remove debugging output from Password test
SelectList test is finalized. Extect auto_check to handle array and scalar accesses to the Form data post processors
This commit is contained in:
parent
2359bd5738
commit
6a035e44b0
3 changed files with 90 additions and 26 deletions
|
|
@ -69,8 +69,6 @@ is(scalar @inputs, 1, 'The form has 1 input');
|
||||||
|
|
||||||
my $input = $inputs[0];
|
my $input = $inputs[0];
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
diag(Dumper $input);
|
|
||||||
diag($html);
|
|
||||||
is($input->name, 'TestText', 'Checking input name');
|
is($input->name, 'TestText', 'Checking input name');
|
||||||
is($input->type, $formType, 'Checking input type');
|
is($input->type, $formType, 'Checking input type');
|
||||||
is($input->value, 'Some text in here', 'Checking default value');
|
is($input->value, 'Some text in here', 'Checking default value');
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,16 @@ my %testBlock;
|
||||||
tie %testBlock, 'Tie::IxHash';
|
tie %testBlock, 'Tie::IxHash';
|
||||||
|
|
||||||
%testBlock = (
|
%testBlock = (
|
||||||
#INT1 => [ '-123456', 'EQUAL', 'valid, negative integer'],
|
LIST1 => [ [qw/a/], 'a', 'single element array, scalar', 'SCALAR'],
|
||||||
#INT2 => [ '+123456', 0, 'reject explicitly positive integer'],
|
LIST2 => [ [qw/a/], 'EQUAL', 'single element array, array', 'ARRAY'],
|
||||||
|
LIST3 => [ [qw/a b c/], "a\nb\nc", 'multi element array, scalar', 'SCALAR'],
|
||||||
|
LIST4 => [ [qw/a b c/], 'EQUAL', 'multi element array, array', 'ARRAY'],
|
||||||
);
|
);
|
||||||
|
|
||||||
my $formClass = 'WebGUI::Form::SelectList';
|
my $formClass = 'WebGUI::Form::SelectList';
|
||||||
my $formType = 'SelectList';
|
my $formType = 'SelectList';
|
||||||
|
|
||||||
my $numTests = 5 + scalar keys %testBlock;
|
my $numTests = 11 + scalar keys %testBlock;
|
||||||
|
|
||||||
diag("Planning on running $numTests tests\n");
|
diag("Planning on running $numTests tests\n");
|
||||||
|
|
||||||
|
|
@ -53,40 +55,91 @@ my $html = join "\n",
|
||||||
$header,
|
$header,
|
||||||
$formClass->new($session, {
|
$formClass->new($session, {
|
||||||
name => 'ListMultiple',
|
name => 'ListMultiple',
|
||||||
options => { a=>'a', b=>'b', c=>'c', d=>'d', e=>'e' },
|
options => { a=>'aa', b=>'bb', c=>'cc', d=>'dd', e=>'ee', ''=>'Empty' },
|
||||||
value => [ qw(a c e)],
|
value => [ qw(a c e), ''],
|
||||||
sortByValue => 1,
|
sortByValue => 1,
|
||||||
})->toHtml,
|
})->toHtml,
|
||||||
$footer;
|
$footer;
|
||||||
|
|
||||||
diag($html);
|
|
||||||
|
|
||||||
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
|
|
||||||
##Test Form Generation
|
##Test Form Generation
|
||||||
|
|
||||||
is(scalar @forms, 1, '1 form was parsed');
|
is(scalar @forms, 1, '1 form was parsed');
|
||||||
|
|
||||||
#use Data::Dumper;
|
|
||||||
#diag(Dumper \@forms);
|
|
||||||
|
|
||||||
my $form = $forms[0];
|
my $form = $forms[0];
|
||||||
my @inputs = $form->inputs;
|
|
||||||
is(scalar @inputs, 5, 'The form has 5 inputs');
|
|
||||||
|
|
||||||
#Basic tests
|
|
||||||
|
|
||||||
#use Data::Dumper;
|
#use Data::Dumper;
|
||||||
#diag(Dumper $form);
|
#diag(Dumper $form);
|
||||||
|
my @inputs = $form->inputs;
|
||||||
|
is(scalar @inputs, 6, 'The form has 6 inputs');
|
||||||
|
|
||||||
|
#Basic tests
|
||||||
|
|
||||||
my @options = $form->find_input('ListMultiple');
|
my @options = $form->find_input('ListMultiple');
|
||||||
|
|
||||||
is( scalar(grep {$_->type ne 'option'} @options), 0, 'All inputs are of type option');
|
is( scalar(grep {$_->type ne 'option'} @options), 0, 'All inputs are of type option');
|
||||||
|
|
||||||
my @names = map { $_->name } @options;
|
is( scalar(grep {$_->{multiple} ne '1'} @options), 0, 'All inputs have multiple');
|
||||||
cmp_bag( [@names], [ ('ListMultiple')x5 ], 'correct number of names and names');
|
|
||||||
|
|
||||||
cmp_bag([ $form->param('ListMultiple') ], [qw(a c e)], 'preselected values');
|
my @names = map { $_->name } @options;
|
||||||
|
cmp_deeply( [@names], bag(('ListMultiple')x6), 'correct number of names and names');
|
||||||
|
|
||||||
|
cmp_set([ $form->param('ListMultiple') ], [qw(a c e), ''], 'preselected values in order');
|
||||||
|
|
||||||
my @values = map { $_->possible_values } @options;
|
my @values = map { $_->possible_values } @options;
|
||||||
#cmp_bag([ @values ], [qw(a b c d e), ('')x5], 'list of all options');
|
cmp_bag([ @values ], [qw(a b c d e), '', (undef)x6], 'list of all options');
|
||||||
|
|
||||||
|
my @value_names = map { $_->value_names } @options;
|
||||||
|
cmp_bag([ @value_names ], [qw(aa bb cc dd ee Empty), ('off')x6], 'list of all displayed value names');
|
||||||
|
|
||||||
|
$html = join "\n",
|
||||||
|
$header,
|
||||||
|
$formClass->new($session, {
|
||||||
|
name => 'ListMultiple',
|
||||||
|
options => { a=>'aa', b=>'bb', c=>'cc', d=>'dd', e=>'ee' },
|
||||||
|
defaultValue => [ qw(a b c) ],
|
||||||
|
sortByValue => 1,
|
||||||
|
})->toHtml,
|
||||||
|
$footer;
|
||||||
|
|
||||||
|
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
|
$form = $forms[0];
|
||||||
|
|
||||||
|
cmp_bag([ $form->param('ListMultiple') ], [qw(a b c)], 'defaultValue used if value is blank');
|
||||||
|
|
||||||
|
|
||||||
|
$html = join "\n",
|
||||||
|
$header,
|
||||||
|
$formClass->new($session, {
|
||||||
|
name => 'ListMultiple',
|
||||||
|
options => { a=>'aa', b=>'bb', c=>'cc', d=>'dd', e=>'ee' },
|
||||||
|
value => [ qw(d e) ],
|
||||||
|
defaultValue => [ qw(a b c) ],
|
||||||
|
sortByValue => 1,
|
||||||
|
})->toHtml,
|
||||||
|
$footer;
|
||||||
|
|
||||||
|
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
|
$form = $forms[0];
|
||||||
|
|
||||||
|
cmp_bag([ $form->param('ListMultiple') ], [qw(d e)], 'defaultValue ignored if value is present');
|
||||||
|
|
||||||
|
|
||||||
|
$html = join "\n",
|
||||||
|
$header,
|
||||||
|
$formClass->new($session, {
|
||||||
|
name => 'ListMultiple',
|
||||||
|
options => { a=>'aa', b=>'bb', c=>'cc', d=>'dd', e=>'ee' },
|
||||||
|
value => [ qw(a b c d e) ],
|
||||||
|
sortByValue => 1,
|
||||||
|
})->toHtml,
|
||||||
|
$footer;
|
||||||
|
|
||||||
|
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
|
$form = $forms[0];
|
||||||
|
|
||||||
|
cmp_set([ $form->param('ListMultiple') ], [qw(a b c d e)], 'sorted value check');
|
||||||
|
|
||||||
|
##Test Form Output parsing
|
||||||
|
|
||||||
|
WebGUI::Form_Checking::auto_check($session, $formType, %testBlock);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package WebGUI::Form_Checking;
|
||||||
|
|
||||||
use Test::MockObject;
|
use Test::MockObject;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
|
|
||||||
sub auto_check {
|
sub auto_check {
|
||||||
my ($session, $formType, %testBlock) = @_;
|
my ($session, $formType, %testBlock) = @_;
|
||||||
|
|
@ -11,17 +12,29 @@ sub auto_check {
|
||||||
$request->mock('body',
|
$request->mock('body',
|
||||||
sub {
|
sub {
|
||||||
my ($self, $value) = @_;
|
my ($self, $value) = @_;
|
||||||
return $testBlock{$value}->[0] if (exists $testBlock{$value});
|
return unless exists $testBlock{$value};
|
||||||
return;
|
if (ref $testBlock{$value}->[0] eq "ARRAY") {
|
||||||
|
return @{ $testBlock{$value}->[0] };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $testBlock{$value}->[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$session->{_request} = $request;
|
$session->{_request} = $request;
|
||||||
|
|
||||||
foreach my $key (keys %testBlock) {
|
foreach my $key (keys %testBlock) {
|
||||||
my ($testValue, $expected, $comment) = @{ $testBlock{$key} };
|
my ($testValue, $expected, $comment, $dataType) = @{ $testBlock{$key} };
|
||||||
my $value = $session->form->get($key, $formType);
|
$dataType ||= 'SCALAR';
|
||||||
is($value, ($expected eq 'EQUAL' ? $testValue : $expected), $comment);
|
if ($dataType eq 'SCALAR') {
|
||||||
|
my $value = $session->form->get($key, $formType);
|
||||||
|
is($value, ($expected eq 'EQUAL' ? $testValue : $expected), $comment);
|
||||||
|
}
|
||||||
|
elsif ($dataType eq 'ARRAY') {
|
||||||
|
my @value = $session->form->get($key, $formType);
|
||||||
|
cmp_bag(\@value, ($expected eq 'EQUAL' ? $testValue : $expected), $comment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$session->{_request} = $origSessionRequest;
|
$session->{_request} = $origSessionRequest;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue