migrate ship getEditForm to FormBuilder
This commit is contained in:
parent
209a24d985
commit
1d8b1b1b3a
4 changed files with 100 additions and 28 deletions
|
|
@ -71,6 +71,11 @@ WebGUI::Shop::PayDriver
|
||||||
|
|
||||||
getEditForm now returns a WebGUI::FormBuilder object
|
getEditForm now returns a WebGUI::FormBuilder object
|
||||||
|
|
||||||
|
WebGUI::Shop::ShipDriver
|
||||||
|
========================
|
||||||
|
|
||||||
|
getEditForm now returns a WebGUI::FormBuilder object
|
||||||
|
|
||||||
WebGUI::Utility
|
WebGUI::Utility
|
||||||
===============
|
===============
|
||||||
This module has been removed. It had many functions that weren't used, and others have better replacements.
|
This module has been removed. It had many functions that weren't used, and others have better replacements.
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ sub www_manage {
|
||||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"addDriver"})
|
.WebGUI::Form::hidden($session, {name=>"method", value=>"addDriver"})
|
||||||
.WebGUI::Form::selectBox($session, {name=>"className", options=>$self->getDrivers})
|
.WebGUI::Form::selectBox($session, {name=>"className", options=>$self->getDrivers})
|
||||||
.WebGUI::Form::submit($session, {value=>$i18n->get("add shipper")})
|
.WebGUI::Form::submit($session, {name => 'add', value=>$i18n->get("add shipper")})
|
||||||
.WebGUI::Form::formFooter($session);
|
.WebGUI::Form::formFooter($session);
|
||||||
my $hasShipper = 0;
|
my $hasShipper = 0;
|
||||||
foreach my $shipper (@{$self->getShippers}) {
|
foreach my $shipper (@{$self->getShippers}) {
|
||||||
|
|
@ -282,14 +282,14 @@ sub www_manage {
|
||||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"deleteDriver"})
|
.WebGUI::Form::hidden($session, {name=>"method", value=>"deleteDriver"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
||||||
.WebGUI::Form::submit($session, {value=>$i18n->get("delete"), extras=>'class="backwardButton"'})
|
.WebGUI::Form::submit($session, {name => 'delete', value=>$i18n->get("delete"), extras=>'class="backwardButton"'})
|
||||||
.WebGUI::Form::formFooter($session)
|
.WebGUI::Form::formFooter($session)
|
||||||
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"'})
|
.WebGUI::Form::formHeader($session, {extras=>'style="float: left;"'})
|
||||||
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
.WebGUI::Form::hidden($session, {name=>"shop", value=>"ship"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"method", value=>"do"})
|
.WebGUI::Form::hidden($session, {name=>"method", value=>"do"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"do", value=>"edit"})
|
.WebGUI::Form::hidden($session, {name=>"do", value=>"edit"})
|
||||||
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
.WebGUI::Form::hidden($session, {name=>"driverId", value=>$shipper->getId})
|
||||||
.WebGUI::Form::submit($session, {value=>$i18n->get("edit"), extras=>'class="normalButton"'})
|
.WebGUI::Form::submit($session, {name => 'edit', value=>$i18n->get("edit"), extras=>'class="normalButton"'})
|
||||||
.WebGUI::Form::formFooter($session)
|
.WebGUI::Form::formFooter($session)
|
||||||
.' '
|
.' '
|
||||||
.$shipper->get("label")
|
.$shipper->get("label")
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use strict;
|
||||||
use Carp qw(croak);
|
use Carp qw(croak);
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
use WebGUI::HTMLForm;
|
use WebGUI::FormBuilder;
|
||||||
use WebGUI::Exception::Shop;
|
use WebGUI::Exception::Shop;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
|
||||||
|
|
@ -199,27 +199,26 @@ Returns the configuration form for the options of this plugin.
|
||||||
|
|
||||||
sub getEditForm {
|
sub getEditForm {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
my $form = WebGUI::HTMLForm->new($self->session);
|
my $form = WebGUI::FormBuilder->new($self->session, action => $self->session->url->page );
|
||||||
$form->submit;
|
$form->addField( "submit", name => "submit" );
|
||||||
|
|
||||||
$form->hidden(name => 'shop',value => "ship");
|
$form->addField( "hidden", name => 'shop', value => "ship");
|
||||||
$form->hidden(name => 'method',value => "do");
|
$form->addField( "hidden", name => 'method', value => "do");
|
||||||
$form->hidden(name => 'do',value => "editSave");
|
$form->addField( "hidden", name => 'do', value => "editSave");
|
||||||
$form->hidden(
|
$form->addField( "hidden",
|
||||||
name => 'driverId',
|
name => 'driverId',
|
||||||
value => $self->getId,
|
value => $self->getId,
|
||||||
);
|
);
|
||||||
tie my %form_options, 'Tie::IxHash';
|
|
||||||
foreach my $property_name ($self->getProperties) {
|
foreach my $property_name ($self->getProperties) {
|
||||||
my $property = $self->meta->find_attribute_by_name($property_name);
|
my $property = $self->meta->find_attribute_by_name($property_name);
|
||||||
$form_options{$property_name} = {
|
my %form_options = (
|
||||||
|
name => $property_name,
|
||||||
value => $self->$property_name,
|
value => $self->$property_name,
|
||||||
%{ $self->getFormProperties($property_name)},
|
%{ $self->getFormProperties($property_name)},
|
||||||
};
|
);
|
||||||
|
$form->addField( delete $form_options{fieldType}, %form_options );
|
||||||
}
|
}
|
||||||
my $definition = [ { properties => \%form_options }, ];
|
|
||||||
$form->dynamicForm($definition, 'properties', $self);
|
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
@ -329,8 +328,9 @@ sub www_edit {
|
||||||
my $admin = WebGUI::Shop::Admin->new($session);
|
my $admin = WebGUI::Shop::Admin->new($session);
|
||||||
my $i18n = WebGUI::International->new($session, "Shop");
|
my $i18n = WebGUI::International->new($session, "Shop");
|
||||||
my $form = $self->getEditForm;
|
my $form = $self->getEditForm;
|
||||||
$form->submit;
|
$form->addField( "submit", name => "submit" );
|
||||||
return $admin->getAdminConsole->render($form->print, $i18n->get("shipping methods"));
|
$form->addField( 'csrfToken', name => 'webguiCsrfToken' );
|
||||||
|
return '<h1>' . $i18n->get("shipping methods") . '</h1>' . $form->toHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use HTML::Form;
|
||||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Shop::ShipDriver;
|
use WebGUI::Shop::ShipDriver;
|
||||||
|
use WebGUI::Test::Mechanize;
|
||||||
use Clone;
|
use Clone;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -31,7 +32,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 32;
|
plan tests => 48;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
@ -127,16 +128,16 @@ is($driver->get('label'), 'Slow and dangerous', 'get returns a safe copy of the
|
||||||
|
|
||||||
my $form = $driver->getEditForm;
|
my $form = $driver->getEditForm;
|
||||||
|
|
||||||
isa_ok($form, 'WebGUI::HTMLForm', 'getEditForm returns an HTMLForm object');
|
isa_ok($form, 'WebGUI::FormBuilder', 'getEditForm returns a FormBuilder object');
|
||||||
|
|
||||||
my $html = $form->print;
|
my $html = $form->toHtml;
|
||||||
|
|
||||||
##Any URL is fine, really
|
##Any URL is fine, really
|
||||||
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||||
|
|
||||||
my @inputs = $forms[0]->inputs;
|
my @inputs = $forms[0]->inputs;
|
||||||
is (scalar @inputs, 10, 'getEditForm: the form has 10 controls');
|
is (scalar @inputs, 9, 'getEditForm: the form has 10 controls');
|
||||||
|
|
||||||
my @interestingFeatures;
|
my @interestingFeatures;
|
||||||
foreach my $input (@inputs) {
|
foreach my $input (@inputs) {
|
||||||
|
|
@ -149,11 +150,7 @@ cmp_deeply(
|
||||||
\@interestingFeatures,
|
\@interestingFeatures,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name => 'webguiCsrfToken',
|
name => 'submit',
|
||||||
type => 'hidden',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name => undef,
|
|
||||||
type => 'submit',
|
type => 'submit',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -194,6 +191,76 @@ cmp_deeply(
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
|
||||||
|
$mech->get_ok( '/' );
|
||||||
|
$mech->session->user({ userId => 3 });
|
||||||
|
|
||||||
|
# Get to the management screen
|
||||||
|
$mech->get_ok( '?shop=ship;method=manage' );
|
||||||
|
|
||||||
|
# Click the Add Shipping button
|
||||||
|
$mech->form_with_fields( 'className', 'add' );
|
||||||
|
$mech->select( 'className' => 'WebGUI::Shop::ShipDriver::FlatRate' );
|
||||||
|
$mech->click_ok( 'add' );
|
||||||
|
|
||||||
|
# Fill in the form
|
||||||
|
$mech->submit_form_ok({
|
||||||
|
fields => {
|
||||||
|
label => 'Blue Box',
|
||||||
|
enabled => 1,
|
||||||
|
flatFee => 5.00,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"add a new driver",
|
||||||
|
);
|
||||||
|
|
||||||
|
# Shipping method added!
|
||||||
|
$mech->content_contains( 'Blue Box', 'new shipping label shows up in manage screen' );
|
||||||
|
|
||||||
|
# Find our new shipping driver
|
||||||
|
my $shipdriverId;
|
||||||
|
for my $row ( @{ $session->db->buildArrayRefOfHashRefs( 'SELECT * FROM shipper' ) } ) {
|
||||||
|
my $options = JSON->new->decode( $row->{options} );
|
||||||
|
if ( $options->{label} eq 'Blue Box' ) {
|
||||||
|
$shipdriverId = $row->{shipperId};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ok( my $shipdriver = WebGUI::Shop::ShipDriver::FlatRate->new( $mech->session, $shipdriverId ), 'shipdriver can be instanced' );
|
||||||
|
WebGUI::Test::addToCleanup( $shipdriver );
|
||||||
|
is( $shipdriver->label, 'Blue Box', 'label set correctly' );
|
||||||
|
ok( $shipdriver->enabled, 'driver is enabled' );
|
||||||
|
is( $shipdriver->flatFee, 5.00, 'flat fee added correctly' );
|
||||||
|
|
||||||
|
# Edit an existing ShipDriver
|
||||||
|
# Find the right form and click the Edit button
|
||||||
|
my $formNumber = 1;
|
||||||
|
for my $form ( $mech->forms ) {
|
||||||
|
if ( $form->value( 'do' ) eq 'edit' && $form->value( 'driverId' ) eq $shipdriverId ) {
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$formNumber++;
|
||||||
|
}
|
||||||
|
$mech->submit_form_ok({
|
||||||
|
form_number => $formNumber,
|
||||||
|
}, 'click edit button',
|
||||||
|
);
|
||||||
|
|
||||||
|
# Fill in the form
|
||||||
|
$mech->submit_form_ok({
|
||||||
|
fields => {
|
||||||
|
label => "Brown Box",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"edit shipping method",
|
||||||
|
);
|
||||||
|
|
||||||
|
# Shipping method edited!
|
||||||
|
$mech->content_contains( 'Brown Box', 'new label shows up in manage screen' );
|
||||||
|
ok( my $shipdriver = WebGUI::Shop::ShipDriver::FlatRate->new( $mech->session, $shipdriverId ), 'shipdriver can be instanced' );
|
||||||
|
is( $shipdriver->label, 'Brown Box', 'label set correctly' );
|
||||||
|
ok( $shipdriver->enabled, 'driver is enabled' );
|
||||||
|
is( $shipdriver->flatFee, 5.00, 'flat fee still only $5' );
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# new
|
# new
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue