migrate EMSToken to FormBuilder

This commit is contained in:
Doug Bell 2011-01-25 12:02:59 -06:00
parent 6729cb0621
commit 1d9911ff0c
2 changed files with 60 additions and 6 deletions

View file

@ -186,12 +186,12 @@ sub view {
# build the add to cart form
if ($form->get('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->integer(name=>'quantity', value=>1, label=>$i18n->get('quantity','Shop'));
$addToCart->submit(value=>$i18n->get('add to cart','Shop'), label=>$self->getPrice);
$output .= $addToCart->print;
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( "integer", name=>'quantity', value=>1, label=>$i18n->get('quantity','Shop'));
$f->addField( "submit", value=>$i18n->get('add to cart','Shop'), label=>$self->getPrice);
$output .= $f->toHtml;
}
return $output;

54
t/Asset/Sku/EMSToken.t Normal file
View file

@ -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 EMSToken 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 $token = $ems->addChild({
className => 'WebGUI::Asset::Sku::EMSToken',
});
#----------------------------------------------------------------------------
# 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( $token->getUrl( 'badgeId=' . $badge->getId ) );
$mech->submit_form_ok({
fields => { },
});
my $cart = WebGUI::Shop::Cart->newBySession( $mech->session );
ok( $cart->getItemsByAssetId([ $token->getId ])->[0]->getId, $token->getId );
done_testing;
#vim:ft=perl