Update the test for the new ShipDriver code. Fix edit form generating code.
This commit is contained in:
parent
6e5dc09165
commit
ad13a9134e
2 changed files with 19 additions and 138 deletions
|
|
@ -206,10 +206,6 @@ sub getEditForm {
|
||||||
$form->hidden(name => 'shop',value => "ship");
|
$form->hidden(name => 'shop',value => "ship");
|
||||||
$form->hidden(name => 'method',value => "do");
|
$form->hidden(name => 'method',value => "do");
|
||||||
$form->hidden(name => 'do',value => "editSave");
|
$form->hidden(name => 'do',value => "editSave");
|
||||||
$form->hidden(
|
|
||||||
name => 'className',
|
|
||||||
value => $self->className,
|
|
||||||
);
|
|
||||||
$form->hidden(
|
$form->hidden(
|
||||||
name => 'driverId',
|
name => 'driverId',
|
||||||
value => $self->getId,
|
value => $self->getId,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ 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 Clone;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
|
|
@ -29,125 +31,41 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 44;
|
plan tests => 32;
|
||||||
plan tests => 1 + $tests;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
||||||
my $e;
|
my $e;
|
||||||
|
|
||||||
my $loaded = use_ok('WebGUI::Shop::ShipDriver');
|
|
||||||
|
|
||||||
my $storage;
|
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
# definition
|
# new
|
||||||
#
|
|
||||||
#######################################################################
|
|
||||||
|
|
||||||
my $definition;
|
|
||||||
|
|
||||||
eval { $definition = WebGUI::Shop::ShipDriver->definition(); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => 'Must provide a session variable',
|
|
||||||
),
|
|
||||||
'definition: requires a session variable',
|
|
||||||
);
|
|
||||||
|
|
||||||
$definition = WebGUI::Shop::ShipDriver->definition($session);
|
|
||||||
|
|
||||||
cmp_deeply(
|
|
||||||
$definition,
|
|
||||||
[ {
|
|
||||||
name => 'Shipper Driver',
|
|
||||||
properties => {
|
|
||||||
label => {
|
|
||||||
fieldType => 'text',
|
|
||||||
label => ignore(),
|
|
||||||
hoverHelp => ignore(),
|
|
||||||
defaultValue => undef,
|
|
||||||
},
|
|
||||||
enabled => {
|
|
||||||
fieldType => 'yesNo',
|
|
||||||
label => ignore(),
|
|
||||||
hoverHelp => ignore(),
|
|
||||||
defaultValue => 1,
|
|
||||||
},
|
|
||||||
groupToUse => {
|
|
||||||
fieldType => 'group',
|
|
||||||
label => ignore(),
|
|
||||||
hoverHelp => ignore(),
|
|
||||||
defaultValue => 7,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} ],
|
|
||||||
,
|
|
||||||
'Definition returns an array of hashrefs',
|
|
||||||
);
|
|
||||||
|
|
||||||
$definition = WebGUI::Shop::ShipDriver->definition($session, [ { name => 'Red' }]);
|
|
||||||
|
|
||||||
cmp_deeply(
|
|
||||||
$definition,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name => 'Red',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name => 'Shipper Driver',
|
|
||||||
properties => ignore(),
|
|
||||||
}
|
|
||||||
],
|
|
||||||
,
|
|
||||||
'New data is appended correctly',
|
|
||||||
);
|
|
||||||
|
|
||||||
#######################################################################
|
|
||||||
#
|
|
||||||
# create
|
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
my $driver;
|
my $driver;
|
||||||
|
|
||||||
eval { $driver = WebGUI::Shop::ShipDriver->create(); };
|
eval { $driver = WebGUI::Shop::ShipDriver->new(); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a session object');
|
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a session object');
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$e,
|
$e,
|
||||||
methods(
|
methods(
|
||||||
error => 'Must provide a session variable',
|
error => 'Must provide a session variable',
|
||||||
),
|
),
|
||||||
'create takes exception to not giving it a session object',
|
'new takes exception to not giving it a session object',
|
||||||
);
|
);
|
||||||
|
|
||||||
eval { $driver = WebGUI::Shop::ShipDriver->create($session); };
|
eval { $driver = WebGUI::Shop::ShipDriver->new($session); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a hashref of options');
|
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a hashref of options');
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$e,
|
$e,
|
||||||
methods(
|
methods(
|
||||||
error => 'Must provide a hashref of options',
|
error => 'Must provide a shipperId',
|
||||||
),
|
),
|
||||||
'create takes exception to not giving it a hashref of options',
|
'new takes exception to not giving it a shipperId',
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
eval { $driver = WebGUI::Shop::ShipDriver->create($session, {}); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it an empty hashref of options');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => 'Must provide a hashref of options',
|
|
||||||
),
|
|
||||||
'create takes exception to not giving it an empty hashref of options',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
my $options = {
|
my $options = {
|
||||||
|
|
@ -156,7 +74,8 @@ my $options = {
|
||||||
groupToUse => 7,
|
groupToUse => 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
|
$driver = WebGUI::Shop::ShipDriver->new( $session, Clone::clone($options) );
|
||||||
|
$driver->write;
|
||||||
WebGUI::Test->addToCleanup($driver);
|
WebGUI::Test->addToCleanup($driver);
|
||||||
|
|
||||||
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
|
||||||
|
|
@ -167,8 +86,7 @@ is($session->getId, $driver->session->getId, 'session method returns OUR session
|
||||||
|
|
||||||
like($driver->getId, $session->id->getValidator, 'got a valid GUID for shipperId');
|
like($driver->getId, $session->id->getValidator, 'got a valid GUID for shipperId');
|
||||||
|
|
||||||
|
cmp_deeply($driver->get, { %{$options}, shipperId=>ignore()} , 'get works');
|
||||||
cmp_deeply($driver->get, $options, 'options accessor works');
|
|
||||||
|
|
||||||
my $dbData = $session->db->quickHashRef('select * from shipper where shipperId=?',[$driver->getId]);
|
my $dbData = $session->db->quickHashRef('select * from shipper where shipperId=?',[$driver->getId]);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
|
|
@ -187,7 +105,7 @@ cmp_deeply(
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
is (WebGUI::Shop::ShipDriver->getName($session), 'Shipper Driver', 'getName returns the human readable name of this driver');
|
is (WebGUI::Shop::ShipDriver->getName($session), 'Shipping Driver', 'getName returns the human readable name of this driver');
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
#
|
#
|
||||||
|
|
@ -238,10 +156,6 @@ cmp_deeply(
|
||||||
name => undef,
|
name => undef,
|
||||||
type => 'submit',
|
type => 'submit',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name => 'driverId',
|
|
||||||
type => 'hidden',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name => 'shop',
|
name => 'shop',
|
||||||
type => 'hidden',
|
type => 'hidden',
|
||||||
|
|
@ -254,6 +168,10 @@ cmp_deeply(
|
||||||
name => 'do',
|
name => 'do',
|
||||||
type => 'hidden',
|
type => 'hidden',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name => 'driverId',
|
||||||
|
type => 'hidden',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name => 'label',
|
name => 'label',
|
||||||
type => 'text',
|
type => 'text',
|
||||||
|
|
@ -284,28 +202,6 @@ cmp_deeply(
|
||||||
|
|
||||||
my $oldDriver;
|
my $oldDriver;
|
||||||
|
|
||||||
eval { $oldDriver = WebGUI::Shop::ShipDriver->new(); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a session object');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => 'Must provide a session variable',
|
|
||||||
),
|
|
||||||
'new takes exception to not giving it a session object',
|
|
||||||
);
|
|
||||||
|
|
||||||
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a shipperId');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => 'Must provide a shipperId',
|
|
||||||
),
|
|
||||||
'new takes exception to not giving it a shipperId',
|
|
||||||
);
|
|
||||||
|
|
||||||
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, 'notEverAnId'); };
|
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, 'notEverAnId'); };
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::ObjectNotFound', 'new croaks unless the requested shipperId object exists in the db');
|
isa_ok($e, 'WebGUI::Error::ObjectNotFound', 'new croaks unless the requested shipperId object exists in the db');
|
||||||
|
|
@ -339,17 +235,6 @@ like ($@, qr/^You must override the calculate method/, 'calculate croaks to forc
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
eval { $driver->update(); };
|
|
||||||
$e = Exception::Class->caught();
|
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidParam', 'update takes exception to not giving it a hashref of options');
|
|
||||||
cmp_deeply(
|
|
||||||
$e,
|
|
||||||
methods(
|
|
||||||
error => 'update was not sent a hashref of options to store in the database',
|
|
||||||
),
|
|
||||||
'update takes exception to not giving it a hashref of options',
|
|
||||||
);
|
|
||||||
|
|
||||||
isa_ok( $driver->get(), 'HASH', 'get returns a hashref if called with no param');
|
isa_ok( $driver->get(), 'HASH', 'get returns a hashref if called with no param');
|
||||||
|
|
||||||
is($driver->get('groupToUse'), 7, '... default group is 7');
|
is($driver->get('groupToUse'), 7, '... default group is 7');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue