Test updates, code fixes. Failing 6 tests

This commit is contained in:
Colin Kuskie 2010-09-24 16:52:46 -07:00
parent 7aabbb07d7
commit 280c8b3047
2 changed files with 96 additions and 185 deletions

View file

@ -111,7 +111,8 @@ around BUILDARGS => sub {
unless exists $properties->{options} and $properties->{options}; unless exists $properties->{options} and $properties->{options};
my $options = from_json($properties->{options}); my $options = from_json($properties->{options});
$options->{session} = $session; $options->{session} = $session;
$options->{paymentGatewayId} = $paymentGatewayId;
return $class->$orig($options); return $class->$orig($options);
}; };
@ -241,7 +242,7 @@ to do calculations.
=cut =cut
sub className { sub className {
return ref $_->[0]; return ref $_[0];
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -670,6 +671,7 @@ sub write {
my $properties = $self->get(); my $properties = $self->get();
delete $properties->{session}; delete $properties->{session};
delete $properties->{paymentGatewayId};
my $jsonOptions = to_json($properties); my $jsonOptions = to_json($properties);
$self->session->db->setRow($self->tableName, 'paymentGatewayId', { $self->session->db->setRow($self->tableName, 'paymentGatewayId', {
paymentGatewayId => $self->paymentGatewayId, paymentGatewayId => $self->paymentGatewayId,

View file

@ -28,85 +28,8 @@ use WebGUI::Shop::PayDriver;
# Init # Init
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 55;
#----------------------------------------------------------------------------
# figure out if the test can actually run
my $e; my $e;
#######################################################################
#
# definition
#
#######################################################################
my $definition;
eval { $definition = WebGUI::Shop::PayDriver->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::PayDriver->definition($session);
use Data::Dumper;
cmp_deeply (
$definition,
[ {
name => 'Payment Driver',
properties => {
label => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => "Credit Card",
},
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::PayDriver->definition($session, [ { name => 'Red' }]);
cmp_deeply (
$definition,
[
{
name => 'Red',
},
{
name => 'Payment Driver',
properties => ignore(),
}
],
,
'New data is appended correctly',
);
####################################################################### #######################################################################
# #
# create # create
@ -117,26 +40,15 @@ my $driver;
# Test incorrect for parameters # Test incorrect for parameters
eval { $driver = WebGUI::Shop::PayDriver->create(); }; eval { $driver = WebGUI::Shop::PayDriver->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::PayDriver->create($session, {}); };
$e = Exception::Class->caught();
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create takes exception to 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',
); );
# Test functionality # Test functionality
@ -144,15 +56,15 @@ cmp_deeply (
my $options = { my $options = {
label => 'Fast and harmless', label => 'Fast and harmless',
enabled => 1, enabled => 1,
group => 3, groupToUse => 3,
receiptMessage => 'Pannenkoeken zijn nog lekkerder met spek',
}; };
$driver = WebGUI::Shop::PayDriver->create( $session, $options ); $driver = WebGUI::Shop::PayDriver->new( $session, $options );
isa_ok ($driver, 'WebGUI::Shop::PayDriver', 'create creates WebGUI::Shop::PayDriver object'); isa_ok ($driver, 'WebGUI::Shop::PayDriver', 'new creates WebGUI::Shop::PayDriver object');
like($driver->getId, $session->id->getValidator, 'driver id is a valid GUID'); like($driver->getId, $session->id->getValidator, 'driver id is a valid GUID');
$driver->write;
my $dbData = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [ $driver->getId ]); my $dbData = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [ $driver->getId ]);
cmp_deeply ( cmp_deeply (
@ -160,7 +72,7 @@ cmp_deeply (
{ {
paymentGatewayId => $driver->getId, paymentGatewayId => $driver->getId,
className => ref $driver, className => ref $driver,
options => q|{"group":3,"receiptMessage":"Pannenkoeken zijn nog lekkerder met spek","label":"Fast and harmless","enabled":1}|, options => q|{"groupToUse":3,"label":"Fast and harmless","enabled":1}|,
}, },
'Correct data written to the db', 'Correct data written to the db',
); );
@ -193,14 +105,6 @@ is ($driver->getId, $driver->paymentGatewayId, 'getId retur
is ($driver->className, ref $driver, 'className property set correctly'); is ($driver->className, ref $driver, 'className property set correctly');
#######################################################################
#
# options
#
#######################################################################
cmp_deeply ($driver->options, $options, 'options accessor works');
####################################################################### #######################################################################
# #
# getName # getName
@ -218,7 +122,15 @@ cmp_deeply (
'getName requires a session object passed to it', 'getName requires a session object passed to it',
); );
is (WebGUI::Shop::PayDriver->getName($session), 'Payment Driver', 'getName returns the human readable name of this driver'); is (WebGUI::Shop::PayDriver->getName($session), 'Payment Driver', 'getName returns the human readable name of this driver');
#######################################################################
#
# method checks
#
#######################################################################
can_ok $driver, qw/get set update write getName className label enabled paymentGatewayId groupToUse/;
####################################################################### #######################################################################
# #
@ -226,9 +138,8 @@ is (WebGUI::Shop::PayDriver->getName($session), 'Payment Driver', 'getN
# #
####################################################################### #######################################################################
cmp_deeply ($driver->get, $driver->options, 'get works like the options method with no param passed'); cmp_deeply ($driver->get, $options, 'get works like the options method with no param passed');
is ($driver->get('enabled'), 1, 'get the enabled entry from the options'); is ($driver->get('label'), 'Fast and harmless', 'get the label entry from the options');
is ($driver->get('label'), 'Fast and harmless', 'get the label entry from the options');
my $optionsCopy = $driver->get; my $optionsCopy = $driver->get;
$optionsCopy->{label} = 'And now for something completely different'; $optionsCopy->{label} = 'And now for something completely different';
@ -247,7 +158,6 @@ isnt(
my $cart = $driver->getCart; my $cart = $driver->getCart;
WebGUI::Test->addToCleanup($cart); WebGUI::Test->addToCleanup($cart);
isa_ok ($cart, 'WebGUI::Shop::Cart', 'getCart returns an instantiated WebGUI::Shop::Cart object'); isa_ok ($cart, 'WebGUI::Shop::Cart', 'getCart returns an instantiated WebGUI::Shop::Cart object');
WebGUI::Test->addToCleanup($cart);
####################################################################### #######################################################################
# #
@ -255,77 +165,77 @@ WebGUI::Test->addToCleanup($cart);
# #
####################################################################### #######################################################################
my $form = $driver->getEditForm; #my $form = $driver->getEditForm;
#
isa_ok ($form, 'WebGUI::HTMLForm', 'getEditForm returns an HTMLForm object'); #isa_ok ($form, 'WebGUI::HTMLForm', 'getEditForm returns an HTMLForm object');
#
my $html = $form->print; #my $html = $form->print;
#
##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, 11, 'getEditForm: the form has 11 controls'); #is (scalar @inputs, 11, 'getEditForm: the form has 11 controls');
#
my @interestingFeatures; #my @interestingFeatures;
foreach my $input (@inputs) { #foreach my $input (@inputs) {
my $name = $input->name; # my $name = $input->name;
my $type = $input->type; # my $type = $input->type;
push @interestingFeatures, { name => $name, type => $type }; # push @interestingFeatures, { name => $name, type => $type };
} #}
#
cmp_deeply( #cmp_deeply(
\@interestingFeatures, # \@interestingFeatures,
[ # [
{ # {
name => 'webguiCsrfToken', # name => 'webguiCsrfToken',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => undef, # name => undef,
type => 'submit', # type => 'submit',
}, # },
{ # {
name => 'shop', # name => 'shop',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => 'method', # name => 'method',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => 'do', # name => 'do',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => 'paymentGatewayId', # name => 'paymentGatewayId',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => 'className', # name => 'className',
type => 'hidden', # type => 'hidden',
}, # },
{ # {
name => 'label', # name => 'label',
type => 'text', # type => 'text',
}, # },
{ # {
name => 'enabled', # name => 'enabled',
type => 'radio', # type => 'radio',
}, # },
{ # {
name => 'groupToUse', # name => 'groupToUse',
type => 'option', # type => 'option',
}, # },
{ # {
name => '__groupToUse_isIn', # name => '__groupToUse_isIn',
type => 'hidden', # type => 'hidden',
}, # },
], # ],
'getEditForm made the correct form with all the elements' # 'getEditForm made the correct form with all the elements'
#
); #);
####################################################################### #######################################################################
@ -374,7 +284,7 @@ my $driverCopy = WebGUI::Shop::PayDriver->new($session, $driver->getId);
is ($driver->getId, $driverCopy->getId, 'same id'); is ($driver->getId, $driverCopy->getId, 'same id');
is ($driver->className, $driverCopy->className, 'same className'); is ($driver->className, $driverCopy->className, 'same className');
cmp_deeply ($driver->options, $driverCopy->options, 'same options'); cmp_deeply ($driver->get, $driverCopy->get, 'same properties');
TODO: { TODO: {
local $TODO = 'tests for new'; local $TODO = 'tests for new';
@ -412,7 +322,6 @@ my $storedJson = $session->db->quickScalar('select options from paymentGateway w
cmp_deeply( cmp_deeply(
$newOptions, $newOptions,
from_json($storedJson), from_json($storedJson),
,
'update() actually stores data', 'update() actually stores data',
); );
@ -528,4 +437,4 @@ is ($count, 0, 'delete deleted the object');
undef $driver; undef $driver;
done_testing;