Begin work of converting ITransact over to Moose.

This commit is contained in:
Colin Kuskie 2010-10-01 08:24:07 -07:00
parent a2103e8036
commit 4715e1c8ef
2 changed files with 46 additions and 233 deletions

View file

@ -35,8 +35,6 @@ $session->user({userId => 3});
#----------------------------------------------------------------------------
# Tests
plan tests => 28;
#----------------------------------------------------------------------------
# figure out if the test can actually run
@ -101,158 +99,6 @@ $cart->update({
shipperId => $shipper->getId,
});
#######################################################################
#
# definition
#
#######################################################################
note('Testing definition');
my $definition;
eval { $definition = WebGUI::Shop::PayDriver::ITransact->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',
);
#######################################################################
#
# create
#
#######################################################################
my $driver;
# Test incorrect for parameters
eval { $driver = WebGUI::Shop::PayDriver::ITransact->create(); };
$e = Exception::Class->caught();
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'create 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::ITransact->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',
);
my $vendorId = $session->config->get("testing/ITransact/vendorId");
my $password = $session->config->get("testing/ITransact/password");
my $hasTestAccount = $vendorId && $password;
if (!$vendorId) {
$vendorId = "joeUser";
}
if (!$password) {
$password = "joePass";
}
my $options = {
label => 'Fast and harmless',
enabled => 1,
groupToUse => 3,
vendorId => $vendorId,
password => $password,
useCVV2 => 1,
};
$driver = WebGUI::Shop::PayDriver::ITransact->create( $session, $options );
isa_ok ($driver, 'WebGUI::Shop::PayDriver::ITransact', 'create creates WebGUI::Shop::PayDriver object');
like($driver->getId, $session->id->getValidator, 'driver id is a valid GUID');
#######################################################################
#
# session
#
#######################################################################
isa_ok ($driver->session, 'WebGUI::Session', 'session method returns a session object');
is ($session->getId, $driver->session->getId, 'session method returns OUR session object');
#######################################################################
#
# paymentGatewayId, getId
#
#######################################################################
like ($driver->paymentGatewayId, $session->id->getValidator, 'got a valid GUID for paymentGatewayId');
is ($driver->getId, $driver->paymentGatewayId, 'getId returns the same thing as paymentGatewayId');
#######################################################################
#
# className
#
#######################################################################
is ($driver->className, ref $driver, 'className property set correctly');
#######################################################################
#
# options
#
#######################################################################
cmp_deeply(
$driver->options,
superhashof( $options ),
'options accessor works'
);
#######################################################################
#
# getName
#
#######################################################################
eval { WebGUI::Shop::PayDriver::ITransact->getName(); };
$e = Exception::Class->caught();
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'getName requires a session object passed to it');
cmp_deeply (
$e,
methods(
error => 'Must provide a session variable',
),
'getName requires a session object passed to it',
);
is(WebGUI::Shop::PayDriver::ITransact->getName($session), 'Credit Card (ITransact)', 'getName returns the human readable name of this driver');
#######################################################################
#
# get
#
#######################################################################
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');
my $optionsCopy = $driver->get;
$optionsCopy->{label} = 'And now for something completely different';
isnt(
$driver->get('label'),
'And now for something completely different',
'hashref returned by get() is a copy of the internal hashref'
);
#######################################################################
#
# _generatePaymentRequestXML
@ -317,20 +163,6 @@ SKIP: {
ok( $response->is_success, '... was successful');
}
#######################################################################
#
# delete
#
#######################################################################
$driver->delete;
my $count = $session->db->quickScalar('select count(*) from paymentGateway where paymentGatewayId=?', [
$driver->paymentGatewayId
]);
is ($count, 0, 'delete deleted the object');
undef $driver;
done_testing;
#vim:ft=perl