diff --git a/lib/WebGUI/Form/Checkbox.pm b/lib/WebGUI/Form/Checkbox.pm index 3e56dc8d9..2931971a2 100644 --- a/lib/WebGUI/Form/Checkbox.pm +++ b/lib/WebGUI/Form/Checkbox.pm @@ -118,7 +118,8 @@ Renders and input tag of type checkbox. sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || ''; + my $value = $self->getDefaultValue; + $value = defined $value ? $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($value))) : ''; my $checkedText = $self->get("checked") ? ' checked="checked"' : ''; my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : ''; return 'get("extras")||'').' />'; diff --git a/lib/WebGUI/Form/Hidden.pm b/lib/WebGUI/Form/Hidden.pm index 469cadada..18f10a8f9 100644 --- a/lib/WebGUI/Form/Hidden.pm +++ b/lib/WebGUI/Form/Hidden.pm @@ -97,7 +97,8 @@ Renders an input tag of type hidden. sub toHtmlAsHidden { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || ''; + my $value = $self->getDefaultValue; + $value = defined $value ? $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($value))) : ''; my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : ''; return 'get("extras")||'').$idText.' />'."\n"; } diff --git a/t/Form/Checkbox.t b/t/Form/Checkbox.t index 54af4a8f5..c9d8277b3 100644 --- a/t/Form/Checkbox.t +++ b/t/Form/Checkbox.t @@ -45,7 +45,7 @@ my $testBlock = [ my $formClass = 'WebGUI::Form::Checkbox'; my $formType = 'Checkbox'; -my $numTests = 7 + scalar @{ $testBlock } + 3; +my $numTests = 8 + scalar @{ $testBlock } + 3; plan tests => $numTests; @@ -101,6 +101,18 @@ $html = join "\n", @forms = HTML::Form->parse($html, 'http://www.webgui.org'); is( $forms[0]->param('cbox3'), ' ', 'WRONG: whitespace value'); +$html = join "\n", + $header, + $formClass->new($session, { + name => 'cbox0', + value => 0, + checked => 1, + })->toHtml, + $footer; + +@forms = HTML::Form->parse($html, 'http://www.webgui.org'); +is( $forms[0]->param('cbox0'), 0, 'zero is a valid value'); + ##Test Form Output parsing WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); diff --git a/t/Form/Hidden.t b/t/Form/Hidden.t index 8426d64d0..bc2c2cb45 100644 --- a/t/Form/Hidden.t +++ b/t/Form/Hidden.t @@ -59,11 +59,17 @@ my $testBlock = [ expected => 'EQUAL', comment => 'white space', }, + { + key => 'Hidden6', + testValue => 0, + expected => 'EQUAL', + comment => 'zero', + }, ]; my $formClass = 'WebGUI::Form::Hidden'; -my $numTests = 5 + scalar @{ $testBlock } + 1; +my $numTests = 7 + scalar @{ $testBlock } + 1; plan tests => $numTests; @@ -96,6 +102,20 @@ is($input->value, 'hiddenData', 'Checking default value'); ##no need for secondary checking for now +$html = join "\n", + $header, + $formClass->new($session, { + name => 'hiddenZero', + value => 0, + })->toHtml, + $footer; + +@forms = HTML::Form->parse($html, 'http://www.webgui.org'); +@inputs = $forms[0]->inputs; +$input = $inputs[0]; +is($input->name, 'hiddenZero', 'Checking input name for zero input'); +is($input->value, 0, 'Checking value for zero input'); + ##Test Form Output parsing WebGUI::Form_Checking::auto_check($session, 'Hidden', $testBlock); diff --git a/t/Form/Radio.t b/t/Form/Radio.t index 6dd464e14..734efa540 100644 --- a/t/Form/Radio.t +++ b/t/Form/Radio.t @@ -45,7 +45,7 @@ my $testBlock = [ my $formClass = 'WebGUI::Form::Radio'; my $formType = 'Radio'; -my $numTests = 7 + scalar @{ $testBlock } + 1; +my $numTests = 8 + scalar @{ $testBlock } + 1; plan tests => $numTests; @@ -100,6 +100,18 @@ $html = join "\n", @forms = HTML::Form->parse($html, 'http://www.webgui.org'); is( $forms[0]->param('radio2'), ' ', 'WRONG: whitespace value'); +$html = join "\n", + $header, + $formClass->new($session, { + name => 'radio3', + value => 0, + checked => 1, + })->toHtml, + $footer; + +@forms = HTML::Form->parse($html, 'http://www.webgui.org'); +is( $forms[0]->param('radio3'), 0, 'zero is a valid value'); + ##Test Form Output parsing WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); diff --git a/t/Shop/loadProducts.pl b/t/Shop/loadProducts.pl index 861170eb4..28f564784 100644 --- a/t/Shop/loadProducts.pl +++ b/t/Shop/loadProducts.pl @@ -90,8 +90,7 @@ my $properties4 = { className => 'WebGUI::Asset::Wobject::Product', url => 'four', price => 7.77, - title => 'no product number', - description => 'fourth product', + description => 'no title', }; my $product4 = $root->addChild($properties4); @@ -166,6 +165,24 @@ $productf->setCollateral('Product_feature', 'Product_featureId', { feature => '25% less code', }); +my $propertiesb = { + className => 'WebGUI::Asset::Wobject::Product', + url => 'benefit_Product', + price => 4.44, + title => 'benefit Product', + description => 'benefit Product', +}; + +my $productb = $root->addChild($propertiesb); + +$productb->setCollateral('Product_benefit', 'Product_benefitId', { + benefit => 'holds mixed nuts', +}); + +$productb->setCollateral('Product_benefit', 'Product_benefitId', { + benefit => 'automatic sodium monitoring', +}); + $tag->commit; diag "Done.";