Remove disabled check from all tests because it gives inconsistent

results.  Some forms were returning undef, some were returning 0.

Added a Radio button test.
Added a test to Checkbox that sees if the value (which is displayed to the
user) can be only whitespace.
This commit is contained in:
Colin Kuskie 2006-04-02 19:25:01 +00:00
parent 29635395cf
commit dc2ec6bbdd
13 changed files with 145 additions and 27 deletions

View file

@ -45,7 +45,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Checkbox';
my $formType = 'Checkbox';
my $numTests = 6 + scalar @{ $testBlock } + 1;
my $numTests = 7 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -57,7 +57,7 @@ my $html = join "\n",
$header,
$formClass->new($session, {
name => 'CBox1',
value => 'Check me',
value => 'Checkme',
checked => 1,
})->toHtml,
$footer;
@ -76,8 +76,31 @@ is(scalar @inputs, 1, 'The form has 1 input');
my $input = $inputs[0];
is($input->name, 'CBox1', 'Checking input name');
is($input->type, 'checkbox', 'Checking input type');
is($input->value, 'Check me', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->value, 'Checkme', 'Checking default value');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'cbox2',
value => '024680',
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('cbox2'), '024680', 'numeric values');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'cbox3',
value => ' ',
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('cbox3'), ' ', 'WRONG: whitespace value');
##Test Form Output parsing

View file

@ -46,7 +46,7 @@ my $testBlock = [
my $formType = 'text';
my $formClass = 'WebGUI::Form::Email';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -77,7 +77,6 @@ my $input = $inputs[0];
is($input->name, 'TestEmail', 'Checking input name');
is($input->type, $formType, 'Checking input type');
is($input->value, 'me@nowhere.com', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 255, 'Checking maxlength param, default');

View file

@ -88,7 +88,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Float';
my $formType = 'Float';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -119,7 +119,6 @@ my $input = $inputs[0];
is($input->name, 'TestFloat', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '12.3456', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 11, 'Default size');
is($input->{maxlength}, 14, 'Default maxlength');

View file

@ -63,7 +63,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Hidden';
my $numTests = 6 + scalar @{ $testBlock } + 1;
my $numTests = 5 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -94,7 +94,6 @@ my $input = $inputs[0];
is($input->name, 'TestHidden', 'Checking input name');
is($input->type, 'hidden', 'Checking input type');
is($input->value, 'hiddenData', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
##no need for secondary checking for now

View file

@ -63,7 +63,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Integer';
my $formType = 'Integer';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -94,7 +94,6 @@ my $input = $inputs[0];
is($input->name, 'TestInteger', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '123456', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 11, 'Default size');
is($input->{maxlength}, 11, 'Default maxlength');

View file

@ -45,7 +45,7 @@ my $testBlock = [
my $formType = 'password';
my $formClass = 'WebGUI::Form::Password';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -77,7 +77,6 @@ use Data::Dumper;
is($input->name, 'TestText', 'Checking input name');
is($input->type, $formType, 'Checking input type');
is($input->value, 'Some text in here', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Default size');
is($input->{maxlength}, 35, 'Default maxlength');

View file

@ -87,7 +87,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Phone';
my $formType = 'Phone';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -118,7 +118,6 @@ my $input = $inputs[0];
is($input->name, 'TestPhone', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '(555)867-5309', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Default size');
is($input->{maxlength}, 255, 'Default maxlength');

107
t/Form/Radio.t Normal file
View file

@ -0,0 +1,107 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Form;
use WebGUI::Form::Radio;
use WebGUI::Session;
use HTML::Form;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Radio form elements work
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
# put your tests here
my $testBlock = [
{
key => 'RADIO1',
testValue => 'string1',
expected => 'EQUAL',
comment => 'string check'
},
{
key => 'RADIO2',
testValue => '002300',
expected => 'EQUAL',
comment => 'valid, leading zeroes'
},
];
my $formClass = 'WebGUI::Form::Radio';
my $formType = 'Radio';
my $numTests = 7 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
plan tests => $numTests;
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
my $html = join "\n",
$header,
$formClass->new($session, {
name => 'radio1',
value => 'Selectify',
checked => 1,
})->toHtml,
$footer;
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
##Test Form Generation
is(scalar @forms, 1, '1 form was parsed');
my @inputs = $forms[0]->inputs;
is(scalar @inputs, 1, 'The form has 1 input');
#Basic tests
my $input = $inputs[0];
is($input->name, 'radio1', 'Checking input name');
is($input->type, 'radio', 'Checking input type');
is($input->value, 'Selectify', 'Checking default value');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'radio2',
value => '024680',
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('radio2'), '024680', 'numeric values');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'radio2',
value => ' ',
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('radio2'), ' ', 'WRONG: whitespace value');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);

View file

@ -48,7 +48,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::SelectBox';
my $formType = 'SelectBox';
my $numTests = 9 + scalar @{ $testBlock } + 1;
my $numTests = 8 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -83,7 +83,6 @@ is(scalar @inputs, 1, 'The form has 1 input');
my $input = $form->find_input('ListBox');
is($input->name, 'ListBox', 'Checking input name');
is($input->type, 'option', 'Checking input type');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->value, 'c', 'Checking default value');
is($input->{size}, 1, 'default size');

View file

@ -44,7 +44,7 @@ my $testBlock = [
my $formType = 'text';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -75,7 +75,6 @@ my $input = $inputs[0];
is($input->name, 'TestText', 'Checking input name');
is($input->type, $formType, 'Checking input type');
is($input->value, 'Some text in here', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 255, 'Checking maxlength param, default');

View file

@ -44,7 +44,7 @@ my $testBlock = [
my $formType = 'textarea';
my $numTests = 14 + scalar @{ $testBlock } + 1;
my $numTests = 13 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -75,7 +75,6 @@ my $input = $inputs[0];
is($input->name, 'TestText', 'Checking input name');
is($input->type, $formType, 'Checking input type');
is($input->value, 'Some text in here', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{rows}, 5, 'Default number of rows');
is($input->{cols}, 50, 'Default number of columns');
is($input->{wrap}, 'virtual', 'Default wrap');

View file

@ -74,7 +74,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Url';
my $numTests = 12 + scalar @{ $testBlock } + 1;
my $numTests = 11 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -105,7 +105,6 @@ my $input = $inputs[0];
is($input->name, 'TestUrl', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, 'http://www.webgui.org', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 2048, 'Checking maxlength param, default');

View file

@ -62,7 +62,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Zipcode';
my $numTests = 14 + scalar @{ $testBlock } + 1;
my $numTests = 12 + scalar @{ $testBlock } + 1;
diag("Planning on running $numTests tests\n");
@ -93,7 +93,6 @@ my $input = $inputs[0];
is($input->name, 'TestZip', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '97123-ORST', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 10, 'Checking maxlength param, default');
@ -113,7 +112,6 @@ $input = $inputs[0];
is($input->name, 'TestZip2', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '97229-MXIM', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 12, 'Checking size param, default');
is($input->{maxlength}, 13, 'Checking maxlength param, default');