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

View file

@ -28,85 +28,8 @@ use WebGUI::Shop::PayDriver;
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 55;
#----------------------------------------------------------------------------
# figure out if the test can actually run
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
@ -117,26 +40,15 @@ my $driver;
# Test incorrect for parameters
eval { $driver = WebGUI::Shop::PayDriver->create(); };
eval { $driver = WebGUI::Shop::PayDriver->new(); };
$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 (
$e,
methods(
error => 'Must provide a session variable',
),
'create 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',
'new takes exception to not giving it a session object',
);
# Test functionality
@ -144,15 +56,15 @@ cmp_deeply (
my $options = {
label => 'Fast and harmless',
enabled => 1,
group => 3,
receiptMessage => 'Pannenkoeken zijn nog lekkerder met spek',
groupToUse => 3,
};
$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');
$driver->write;
my $dbData = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [ $driver->getId ]);
cmp_deeply (
@ -160,7 +72,7 @@ cmp_deeply (
{
paymentGatewayId => $driver->getId,
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',
);
@ -193,14 +105,6 @@ is ($driver->getId, $driver->paymentGatewayId, 'getId retur
is ($driver->className, ref $driver, 'className property set correctly');
#######################################################################
#
# options
#
#######################################################################
cmp_deeply ($driver->options, $options, 'options accessor works');
#######################################################################
#
# getName
@ -218,7 +122,15 @@ cmp_deeply (
'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');
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');
cmp_deeply ($driver->get, $options, 'get works like the options method with no param passed');
is ($driver->get('label'), 'Fast and harmless', 'get the label entry from the options');
my $optionsCopy = $driver->get;
$optionsCopy->{label} = 'And now for something completely different';
@ -247,7 +158,6 @@ isnt(
my $cart = $driver->getCart;
WebGUI::Test->addToCleanup($cart);
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;
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, 11, 'getEditForm: the form has 11 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 => 'webguiCsrfToken',
type => 'hidden',
},
{
name => undef,
type => 'submit',
},
{
name => 'shop',
type => 'hidden',
},
{
name => 'method',
type => 'hidden',
},
{
name => 'do',
type => 'hidden',
},
{
name => 'paymentGatewayId',
type => 'hidden',
},
{
name => 'className',
type => 'hidden',
},
{
name => 'label',
type => 'text',
},
{
name => 'enabled',
type => 'radio',
},
{
name => 'groupToUse',
type => 'option',
},
{
name => '__groupToUse_isIn',
type => 'hidden',
},
],
'getEditForm made the correct form with all the elements'
);
#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, 11, 'getEditForm: the form has 11 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 => 'webguiCsrfToken',
# type => 'hidden',
# },
# {
# name => undef,
# type => 'submit',
# },
# {
# name => 'shop',
# type => 'hidden',
# },
# {
# name => 'method',
# type => 'hidden',
# },
# {
# name => 'do',
# type => 'hidden',
# },
# {
# name => 'paymentGatewayId',
# type => 'hidden',
# },
# {
# name => 'className',
# type => 'hidden',
# },
# {
# name => 'label',
# type => 'text',
# },
# {
# name => 'enabled',
# type => 'radio',
# },
# {
# name => 'groupToUse',
# type => 'option',
# },
# {
# name => '__groupToUse_isIn',
# type => 'hidden',
# },
# ],
# '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->className, $driverCopy->className, 'same className');
cmp_deeply ($driver->options, $driverCopy->options, 'same options');
cmp_deeply ($driver->get, $driverCopy->get, 'same properties');
TODO: {
local $TODO = 'tests for new';
@ -412,7 +322,6 @@ my $storedJson = $session->db->quickScalar('select options from paymentGateway w
cmp_deeply(
$newOptions,
from_json($storedJson),
,
'update() actually stores data',
);
@ -528,4 +437,4 @@ is ($count, 0, 'delete deleted the object');
undef $driver;
done_testing;