Merge branch 'PayDriver_cio' into WebGUI8

This commit is contained in:
Colin Kuskie 2010-10-08 14:22:24 -07:00
commit 3af80377e6
15 changed files with 709 additions and 1238 deletions

View file

@ -23,90 +23,14 @@ use HTML::Form;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::PayDriver;
use Clone;
#----------------------------------------------------------------------------
# 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 +41,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 +57,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, Clone::clone($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 +73,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 +106,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 +123,29 @@ 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/;
#######################################################################
#
# default label
#
#######################################################################
$driver->label('');
is $driver->label, $driver->getName($session), 'empty label replaced with plugin name';
$driver->label('untitled');
is $driver->label, $driver->getName($session), 'label=untitled replaced with plugin name';
$driver->label('uNtItLeD');
is $driver->label, $driver->getName($session), '...regardless of case';
$driver->label('Fast and harmless');
#######################################################################
#
@ -226,9 +153,17 @@ 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');
use Data::Dumper;
cmp_deeply(
$driver->get,
{
%{ $options },
paymentGatewayId => ignore(),
},
'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 +182,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);
#######################################################################
#
@ -374,7 +308,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';
@ -387,22 +321,10 @@ TODO: {
#
#######################################################################
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',
);
my $newOptions = {
label => 'Yet another label',
enabled => 0,
group => 4,
receiptMessage => 'Dropjes!',
groupToUse => 4,
};
$driver->update($newOptions);
@ -412,12 +334,10 @@ my $storedJson = $session->db->quickScalar('select options from paymentGateway w
cmp_deeply(
$newOptions,
from_json($storedJson),
,
'update() actually stores data',
);
is( $driver->get('receiptMessage'), 'Dropjes!', '... updates object, receiptMessage');
is( $driver->get('group'), 4, '... updates object, group');
is( $driver->get('groupToUse'), 4, '... updates object, group');
is( $driver->get('enabled'), 0, '... updates object, enabled');
is( $driver->get('label'), 'Yet another label', '... updates object, label');
@ -528,4 +448,32 @@ is ($count, 0, 'delete deleted the object');
undef $driver;
#######################################################################
#
# processPropertiesFromFormPost
#
#######################################################################
$session->request->setup_body({
label => 'form processed driver',
enabled => 1,
groupToUse => 7,
});
my $form_driver = WebGUI::Shop::PayDriver->new($session, {});
WebGUI::Test->addToCleanup($form_driver);
$form_driver->processPropertiesFromFormPost;
cmp_deeply(
$form_driver->get(),
{
label => 'form processed driver',
enabled => 1,
groupToUse => 7,
paymentGatewayId => $form_driver->paymentGatewayId,
},
'form contents processed. Missing form properties inherit defaults'
);
done_testing;

View file

@ -25,6 +25,7 @@ use WebGUI::Shop::PayDriver::ITransact;
use JSON;
use HTML::Form;
use WebGUI::Shop::PayDriver::ITransact;
use XML::Simple;
#----------------------------------------------------------------------------
# Init
@ -35,8 +36,6 @@ $session->user({userId => 3});
#----------------------------------------------------------------------------
# Tests
plan tests => 28;
#----------------------------------------------------------------------------
# figure out if the test can actually run
@ -90,6 +89,7 @@ my $foreignHammer = $rockHammer->setCollateral('variantsJSON', 'variantId', 'new
$versionTag->commit;
WebGUI::Test->addToCleanup($versionTag);
$rockHammer = $rockHammer->cloneFromDb;
my $hammerItem = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
my $ship = WebGUI::Shop::Ship->new($session);
my $cart = WebGUI::Shop::Cart->newBySession($session);
@ -101,58 +101,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;
@ -164,6 +112,20 @@ if (!$password) {
$password = "joePass";
}
#######################################################################
#
# getName
#
#######################################################################
ok(WebGUI::Shop::PayDriver::ITransact->getName($session), 'getName returns a name');
#######################################################################
#
# _generatePaymentRequestXML
#
#######################################################################
my $options = {
label => 'Fast and harmless',
enabled => 1,
@ -172,92 +134,9 @@ my $options = {
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
#
#######################################################################
my $driver = WebGUI::Shop::PayDriver::ITransact->new( $session, $options );
$driver->write;
WebGUI::Test->addToCleanup($driver);
my $dt = WebGUI::DateTime->new($session, time());
$dt->add({ years => 1, });
@ -297,7 +176,10 @@ SKIP: {
my $ok_response = isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
SKIP: {
skip "Skipping response check since we did not get a response", 1 unless $ok_response;
ok( $response->is_success, '... was successful');
ok( $response->is_success, '... response was successful');
my $transactionResult = XMLin( $response->content, SuppressEmpty => '' );
ok defined($transactionResult->{TransactionData}), '... transaction was successful'
or diag $xml.$response->content;
}
}
@ -313,24 +195,17 @@ TODO: {
SKIP: {
skip "Skipping XML requests to ITransact due to lack of userId and password", 2 unless $hasTestAccount;
my $response = eval { $driver->doXmlRequest($xml) };
isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
ok( $response->is_success, '... was successful');
my $ok_response = isa_ok($response, 'HTTP::Response', 'returns a HTTP::Response object');
ok( $response->is_success, '... was successful for two item transaction');
SKIP: {
skip "Skipping response check since we did not get a response", 1 unless $ok_response;
ok( $response->is_success, '... response was successful for a two item transaction');
my $transactionResult = XMLin( $response->content, SuppressEmpty => '' );
ok defined($transactionResult->{TransactionData}), '... transaction was successful'
or diag $xml.$response->content;
}
}
#######################################################################
#
# 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

View file

@ -9,10 +9,6 @@
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use strict;
use Test::More;
use Test::Deep;
@ -30,7 +26,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 45;
plan tests => 12;
#----------------------------------------------------------------------------
# figure out if the test can actually run
@ -39,104 +35,7 @@ my $e;
#######################################################################
#
# definition
#
#######################################################################
note('Testing definition');
my $definition;
eval { $definition = WebGUI::Shop::PayDriver::Ogone->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::Ogone->definition($session);
use Data::Dumper;
my $expectDefinition = {
name => 'Ogone',
properties => {
pspid => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => q{}
},
shaSecret => {
fieldType => 'password',
label => ignore(),
hoverHelp => ignore(),
},
postbackSecret => {
fieldType => 'password',
label => ignore(),
hoverHelp => ignore(),
},
locale => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 'en_US',
maxlength => 5,
size => 5,
},
currency => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 'EUR',
maxlength => 3,
size => 3,
},
useTestMode => {
fieldType => 'yesNo',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 1,
},
summaryTemplateId => {
fieldType => 'template',
label => ignore(),
hoverHelp => ignore(),
defaultValue => ignore(),
namespace => 'Shop/Credentials',
},
},
};
cmp_deeply ( $definition->[0], $expectDefinition, 'Definition returns an array of hashrefs' );
$definition = WebGUI::Shop::PayDriver::Ogone->definition($session, [ { name => 'Ogone First' }]);
cmp_deeply (
$definition,
[
{
name => 'Ogone First',
},
{
name => 'Ogone',
properties => ignore(),
},
{
name => 'Payment Driver',
properties => ignore(),
}
],
,
'New data is appended correctly',
);
#######################################################################
#
# create
# new
#
#######################################################################
@ -144,104 +43,18 @@ my $driver;
# Test incorrect for parameters
eval { $driver = WebGUI::Shop::PayDriver::Ogone->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::Ogone->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
my $signature = '-----BEGIN PKCS7-----
MIIHPwYJKoZIhvcNAQcEoIIHMDCCBywCAQExggE0MIIB
MAIBADCBmDCBkjELMAkGA1UEBhMCVVMxCzAJBgNVBAgT
AkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYD
VQQKEwtQYXlQYWwgSW5jLjEVMBMGA1UECxQMc3RhZ2Ux
X2NlcnRzMRMwEQYDVQQDFApzdGFnZTFfYXBpMRwwGgYJ
KoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMA0GCS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cOj6E1Hq
Ebtelq2tg4HroAHZLWoQ3kc/7IM0LCuWZmgtD5739NSS
0+tOFSdH68sxKsdooR3MFTbdzWhtej5fPKRa6BfHGPjI
9R9NoAQBmaeUuOiPSeVTzXDOKDbZB0sJtmWNeueTD9D0
BOu+vkC1g+HRToc=
-----END PKCS7-----';
my $options = {
label => 'Fast and harmless',
enabled => 1,
group => 3,
receiptMessage => 'Pannenkoeken zijn nog lekkerder met kaas',
vendorId => 'oqapi',
signature => $signature,
groupToUse => 3,
currency => 'EUR',
useSandbox => '0',
emailMessage => 'Thank you very very much'
};
$driver = WebGUI::Shop::PayDriver::Ogone->create( $session, $options );
$driver = WebGUI::Shop::PayDriver::Ogone->new( $session, $options );
WebGUI::Test->addToCleanup($driver);
$driver->write;
isa_ok ($driver, 'WebGUI::Shop::PayDriver::Ogone', 'create creates WebGUI::Shop::PayDriver object');
isa_ok ($driver, 'WebGUI::Shop::PayDriver::Ogone', 'new creates WebGUI::Shop::PayDriver object');
like($driver->getId, $session->id->getValidator, 'driver id is a valid GUID');
my $dbData = $session->db->quickHashRef('select * from paymentGateway where paymentGatewayId=?', [ $driver->getId ]);
@ -259,54 +72,21 @@ my $paymentGatewayOptions = from_json($dbData->{'options'});
cmp_deeply (
$paymentGatewayOptions,
{
"group" => 3,
"receiptMessage" => 'Pannenkoeken zijn nog lekkerder met kaas',
"label" => 'Fast and harmless',
"enabled" => 1,
"vendorId" => 'oqapi',
"signature" => $signature,
"currency" => 'EUR',
"useSandbox" => '0',
"emailMessage" => 'Thank you very very much'
groupToUse => 3,
label => 'Fast and harmless',
enabled => 1,
currency => 'EUR',
pspid => '',
summaryTemplateId => 'jysVZeUR0Bx2NfrKs5sulg',
useTestMode => 1,
locale => 'en_US',
shaSecret => undef,
postbackSecret => undef,
},
'Correct options are written to the db'
);
#######################################################################
#
# 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, $options, 'options accessor works');
#######################################################################
#
# getName
@ -326,24 +106,6 @@ cmp_deeply (
is (WebGUI::Shop::PayDriver::Ogone->getName($session), 'Ogone', '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'
);
#######################################################################
#
# getCart
@ -353,7 +115,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);
#######################################################################
#
@ -461,123 +222,4 @@ cmp_deeply(
);
#######################################################################
#
# new
#
#######################################################################
my $oldDriver;
eval { $oldDriver = WebGUI::Shop::PayDriver::Ogone->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::PayDriver::Ogone->new($session); };
$e = Exception::Class->caught();
isa_ok ($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a paymentGatewayId');
cmp_deeply (
$e,
methods(
error => 'Must provide a paymentGatewayId',
),
'new takes exception to not giving it a paymentGatewayId',
);
eval { $oldDriver = WebGUI::Shop::PayDriver::Ogone->new($session, 'notEverAnId'); };
$e = Exception::Class->caught();
isa_ok ($e, 'WebGUI::Error::ObjectNotFound', 'new croaks unless the requested paymentGatewayId object exists in the db');
cmp_deeply (
$e,
methods(
error => 'paymentGatewayId not found in db',
id => 'notEverAnId',
),
'new croaks unless the requested paymentGatewayId object exists in the db',
);
my $driverCopy = WebGUI::Shop::PayDriver::Ogone->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');
#######################################################################
#
# update
#
#######################################################################
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',
);
my $newOptions = {
label => 'Yet another label',
enabled => 0,
group => 4,
receiptMessage => 'Dropjes!',
};
$driver->update($newOptions);
my $storedOptions = $session->db->quickScalar('select options from paymentGateway where paymentGatewayId=?', [
$driver->getId,
]);
cmp_deeply(
$newOptions,
from_json($storedOptions),
,
'update() actually stores data',
);
#######################################################################
#
# canUse
#
#######################################################################
my $newOptions = {
label => 'Yet another label',
enabled => 1,
group => 4,
receiptMessage => 'Dropjes!',
};
$driver->update($newOptions);
$session->user({userId => 3});
ok($driver->canUse, 'canUse: session->user is used if no argument is passed');
ok(!$driver->canUse({userId => 1}), 'canUse: userId explicit works, visitor cannot use this driver');
#######################################################################
#
# 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;
#vim:ft=perl

View file

@ -21,6 +21,7 @@ use HTML::Form;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::PayDriver::PayPal::PayPalStd;
#----------------------------------------------------------------------------
# Init
@ -29,16 +30,13 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 3;
plan tests => 1 + $tests;
plan tests => 3;
#----------------------------------------------------------------------------
# figure out if the test can actually run
my $e;
my $loaded = use_ok('WebGUI::Shop::PayDriver::PayPal::PayPalStd');
#######################################################################
#
# getName
@ -48,25 +46,15 @@ my $driver;
my $options = {
label => 'PayPal',
enabled => 1,
group => 3,
receiptMessage => 'Pannenkoeken zijn nog lekkerder met spek',
groupToUse => 3,
};
$driver = WebGUI::Shop::PayDriver::PayPal::PayPalStd->create( $session, $options );
$driver = WebGUI::Shop::PayDriver::PayPal::PayPalStd->new( $session, $options );
WebGUI::Test->addToCleanup($driver);
isa_ok ($driver, 'WebGUI::Shop::PayDriver');
isa_ok ($driver, 'WebGUI::Shop::PayDriver::PayPal::PayPalStd');
is($driver->getName($session), 'PayPal', 'getName returns the human readable name of this driver');
#######################################################################
#
# delete
#
#######################################################################
$driver->delete;
undef $driver;
#vim:ft=perl