Add getEditForm to the ShipDriver, and test it.
This commit is contained in:
parent
4ce8cd1a07
commit
c1e0471d51
2 changed files with 79 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ use Class::InsideOut qw{ :std };
|
|||
use Carp qw(croak);
|
||||
use Tie::IxHash;
|
||||
use WebGUI::International;
|
||||
use WebGUI::HTMLForm;
|
||||
use JSON;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -184,7 +185,32 @@ sub get {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getID ( )
|
||||
=head2 getEditForm ( )
|
||||
|
||||
Dynamically generate an HTMLForm based on the contents
|
||||
of the definition sub, and return the form.
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $definition = $self->definition($self->session);
|
||||
my $form = WebGUI::HTMLForm->new($self->session);
|
||||
$form->submit;
|
||||
$form->hidden(
|
||||
name => 'shipperId',
|
||||
value => $self->getId,
|
||||
);
|
||||
$form->hidden(
|
||||
name => 'className',
|
||||
value => $self->className,
|
||||
);
|
||||
$form->dynamicForm($definition, 'fields', $self);
|
||||
return $form;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ( )
|
||||
|
||||
Returns the shipperId. This is an alias for shipperId provided
|
||||
since a lot of WebGUI classes have a getId method.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ use lib "$FindBin::Bin/../lib";
|
|||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use HTML::Form;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 24;
|
||||
my $tests = 28;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -164,6 +166,55 @@ is($driver->get('label'), 'Slow and dangerous', 'get the label entry from the
|
|||
#
|
||||
#######################################################################
|
||||
|
||||
my $form = $driver->getEditForm;
|
||||
|
||||
isa_ok($form, 'WebGUI::HTMLForm', 'getEditForm returns an HTMLForm object');
|
||||
|
||||
my $html = $form->print;
|
||||
|
||||
##Any URL is fine, really
|
||||
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
|
||||
is (scalar @forms, 1, 'getEditForm generates just 1 form');
|
||||
|
||||
my @inputs = $forms[0]->inputs;
|
||||
is (scalar @inputs, 5, 'getEditForm: the form has 5 controls');
|
||||
|
||||
my @interestingFeatures;
|
||||
foreach my $input (@inputs) {
|
||||
my $name = $input->name;
|
||||
my $type = $input->type;
|
||||
push @interestingFeatures, { name => $name, type => $type };
|
||||
}
|
||||
|
||||
cmp_deeply(
|
||||
\@interestingFeatures,
|
||||
[
|
||||
{
|
||||
name => undef,
|
||||
type => 'submit',
|
||||
},
|
||||
{
|
||||
name => 'shipperId',
|
||||
type => 'hidden',
|
||||
},
|
||||
{
|
||||
name => 'className',
|
||||
type => 'hidden',
|
||||
},
|
||||
{
|
||||
name => 'label',
|
||||
type => 'text',
|
||||
},
|
||||
{
|
||||
name => 'enabled',
|
||||
type => 'radio',
|
||||
},
|
||||
],
|
||||
'getEditForm made the correct form with all the elements'
|
||||
|
||||
);
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue