migrate Product www_addAccessory to FormBuilder

This commit is contained in:
Doug Bell 2011-01-25 12:57:16 -06:00
parent 1d9911ff0c
commit a30d9acc25
2 changed files with 53 additions and 17 deletions

View file

@ -12,7 +12,7 @@ package WebGUI::Asset::Sku::Product;
use strict; use strict;
use Tie::IxHash; use Tie::IxHash;
use WebGUI::HTMLForm; use WebGUI::FormBuilder;
use WebGUI::Storage; use WebGUI::Storage;
use WebGUI::SQL; use WebGUI::SQL;
use JSON; use JSON;
@ -879,10 +879,10 @@ the user to select them.
sub www_addAccessory { sub www_addAccessory {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); my $f = WebGUI::FormBuilder->new($self->session,action=>$self->getUrl);
$f->hidden( $f->addField( "hidden",
-name => "func", name => "func",
-value => "addAccessorySave", value => "addAccessorySave",
); );
##Accessories are other Products. Give the user a list of Accessories that ##Accessories are other Products. Give the user a list of Accessories that
##are not already used, nor itself. ##are not already used, nor itself.
@ -906,20 +906,20 @@ sub www_addAccessory {
); );
my $i18n = WebGUI::International->new($self->session,"Asset_Product"); my $i18n = WebGUI::International->new($self->session,"Asset_Product");
$f->selectBox( $f->addField( "selectBox",
-name => "accessoryAccessId", name => "accessoryAccessId",
-options => $accessory, options => $accessory,
-label => $i18n->get(17), label => $i18n->get(17),
-hoverHelp => $i18n->get('17 description'), hoverHelp => $i18n->get('17 description'),
); );
$f->yesNo( $f->addField( "yesNo",
-name => "proceed", name => "proceed",
-label => $i18n->get(18), label => $i18n->get(18),
-hoverHelp => $i18n->get('18 description'), hoverHelp => $i18n->get('18 description'),
); );
$f->submit; $f->addField( "submit" );
return $self->getAdminConsole->render($f->print, "product accessory add/edit"); return $f->toHtml;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -25,6 +25,7 @@ use WebGUI::Session;
use WebGUI::Asset; use WebGUI::Asset;
use WebGUI::Asset::Sku::Product; use WebGUI::Asset::Sku::Product;
use WebGUI::Storage; use WebGUI::Storage;
use WebGUI::Test::Mechanize;
use JSON; use JSON;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -35,7 +36,7 @@ my $session = WebGUI::Test->session;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Tests # Tests
plan tests => 19; # Increment this number for each test you create plan tests => 25; # Increment this number for each test you create
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# put your tests here # put your tests here
@ -44,6 +45,7 @@ my $node = WebGUI::Asset->getRoot($session);
my $product = WebGUI::Test->asset( my $product = WebGUI::Test->asset(
className => "WebGUI::Asset::Sku::Product", className => "WebGUI::Asset::Sku::Product",
title => "Rock Hammer", title => "Rock Hammer",
groupIdEdit => 3,
); );
is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string'); is($product->getThumbnailUrl(), '', 'Product with no image1 property returns the empty string');
@ -173,3 +175,37 @@ cmp_deeply(
}, },
'brochure, warranty and manual vars are blank since their storages are empty' 'brochure, warranty and manual vars are blank since their storages are empty'
); );
#----------------------------------------------------------------------------
# addAccessory
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok( '/' );
$mech->session->user({ userId => 3 });
$mech->get_ok( $product->getUrl( 'func=addAccessory' ) );
$mech->submit_form_ok({
fields => {
accessoryAccessId => $imagedProduct->getId,
proceed => 1,
},
}, 'add imagedProduct as an accessory and add another');
$product = $product->cloneFromDb;
cmp_deeply(
$product->getAllCollateral( 'accessoryJSON' ),
[ { accessoryAssetId => $imagedProduct->getId } ],
);
$mech->submit_form_ok({
fields => {
accessoryAccessId => $viewProduct->getId,
proceed => 0,
},
}, 'add viewProduct and go back' );
$product = $product->cloneFromDb;
cmp_deeply(
$product->getAllCollateral( 'accessoryJSON' ),
[ { accessoryAssetId => $imagedProduct->getId }, { accessoryAssetId => $viewProduct->getId } ],
);