diff --git a/lib/WebGUI/Asset/Sku/EMSRibbon.pm b/lib/WebGUI/Asset/Sku/EMSRibbon.pm index 21f7837a2..b24578145 100644 --- a/lib/WebGUI/Asset/Sku/EMSRibbon.pm +++ b/lib/WebGUI/Asset/Sku/EMSRibbon.pm @@ -36,7 +36,7 @@ property percentageDiscount => ( hoverHelp => ["percentage discount help", 'Asset_EventManagementSystem'], ); -use WebGUI::HTMLForm; +use WebGUI::FormBuilder; =head1 NAME @@ -192,12 +192,12 @@ sub view { .'
'.$self->description.'
'; # build the add to cart form - if ($form->badgeId ne '') { - my $addToCart = WebGUI::HTMLForm->new($self->session, action=>$self->getUrl); - $addToCart->hidden(name=>"func", value=>"addToCart"); - $addToCart->hidden(name=>"badgeId", value=>$form->get('badgeId')); - $addToCart->submit(value=>$i18n->get('add to cart','Shop'), label=>$self->getPrice); - $output .= $addToCart->print; + if ($form->get('badgeId') ne '') { + my $f = WebGUI::FormBuilder->new($self->session, action=>$self->getUrl); + $f->addField( "hidden", name=>"func", value=>"addToCart"); + $f->addField( "hidden", name=>"badgeId", value=>$form->get('badgeId')); + $f->addField( "submit", value=>$i18n->get('add to cart','Shop'), label=>$self->getPrice); + $output .= $f->toHtml; } return $output; diff --git a/t/Asset/Sku/EMSRibbon.t b/t/Asset/Sku/EMSRibbon.t new file mode 100644 index 000000000..1ba793930 --- /dev/null +++ b/t/Asset/Sku/EMSRibbon.t @@ -0,0 +1,54 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 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 +#------------------------------------------------------------------ + +# Test the EMSRibbon asset +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/lib"; +use Test::More; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Test::Mechanize; +use WebGUI::Shop::Cart; +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; +my $ems = WebGUI::Test->asset( className => 'WebGUI::Asset::Wobject::EventManagementSystem' ); +my $badge = $ems->addChild({ + className => 'WebGUI::Asset::Sku::EMSBadge', +}); +my $ribbon = $ems->addChild({ + className => 'WebGUI::Asset::Sku::EMSRibbon', +}); + +#---------------------------------------------------------------------------- +# Tests + +#---------------------------------------------------------------------------- +# Test the addToCart form +my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); +$mech->get_ok( '/' ); +$mech->session->user({ userId => 3 }); +$mech->get_ok( $ribbon->getUrl( 'badgeId=' . $badge->getId ) ); +$mech->submit_form_ok({ + fields => { }, +}); + +my $cart = WebGUI::Shop::Cart->newBySession( $mech->session ); +ok( $cart->getItemsByAssetId([ $ribbon->getId ])->[0]->getId, $ribbon->getId ); + + +done_testing; +#vim:ft=perl