Move email notifications about of PayDriver and into Transaction.  Send
a notification when the cart value is 0 due to shop credit.
This commit is contained in:
Colin Kuskie 2009-10-13 16:37:20 -07:00
parent e46ad0d8fd
commit b3858ef250
12 changed files with 206 additions and 150 deletions

View file

@ -93,19 +93,6 @@ cmp_deeply (
hoverHelp => ignore(),
defaultValue => 7,
},
receiptEmailTemplateId => {
fieldType => 'template',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 'bPz1yk6Y9uwMDMBcmMsSCg',
namespace => 'Shop/EmailReceipt',
},
saleNotificationGroupId => {
fieldType => 'group',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 3,
},
}
} ],
,
@ -286,7 +273,7 @@ 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, 14, 'getEditForm: the form has 14 controls');
is (scalar @inputs, 11, 'getEditForm: the form has 11 controls');
my @interestingFeatures;
foreach my $input (@inputs) {
@ -342,18 +329,6 @@ cmp_deeply(
name => '__groupToUse_isIn',
type => 'hidden',
},
{
name => 'receiptEmailTemplateId',
type => 'option',
},
{
name => 'saleNotificationGroupId',
type => 'option',
},
{
name => '__saleNotificationGroupId_isIn',
type => 'hidden',
},
],
'getEditForm made the correct form with all the elements'

View file

@ -372,7 +372,7 @@ 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, 20, 'getEditForm: the form has 20 controls');
is (scalar @inputs, 17, 'getEditForm: the form has 17 controls');
my @interestingFeatures;
foreach my $input (@inputs) {
@ -428,18 +428,6 @@ cmp_deeply(
name => '__groupToUse_isIn',
type => 'hidden',
},
{
name => 'receiptEmailTemplateId',
type => 'option',
},
{
name => 'saleNotificationGroupId',
type => 'option',
},
{
name => '__saleNotificationGroupId_isIn',
type => 'hidden',
},
{
name => 'pspid',
type => 'text',

View file

@ -21,6 +21,8 @@ use Test::Deep;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::Transaction;
use WebGUI::Inbox;
use Clone qw/clone/;
#----------------------------------------------------------------------------
# Init
@ -30,7 +32,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 68; # Increment this number for each test you create
plan tests => 77; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -64,6 +66,7 @@ my $transaction = WebGUI::Shop::Transaction->create($session,{
paymentDriverLabel => 'kkk',
taxes => 7,
});
addToCleanup($transaction);
# objects work
isa_ok($transaction, "WebGUI::Shop::Transaction");
@ -223,15 +226,72 @@ TODO: {
ok(0, 'test keywords');
}
#######################################################################
#
# sendNotification
#
#######################################################################
my $shopUser = WebGUI::User->create($session);
$shopUser->username('shopUser');
my $shopGroup = WebGUI::Group->new($session, 'new');
my $shopAdmin = WebGUI::User->create($session);
$shopUser->username('shopAdmin');
$shopGroup->addUsers([$shopAdmin->getId]);
addToCleanup($shopUser, $shopAdmin, $shopGroup);
$session->setting->set('shopSaleNotificationGroupId', $shopGroup->getId);
$session->user({userId => $shopUser->getId});
my $trans = WebGUI::Shop::Transaction->create($session, {});
ok($trans->can('sendNotifications'), 'sendNotifications: valid method for transactions');
addToCleanup($trans);
##Disable sending email
my $sendmock = Test::MockObject->new( {} );
$sendmock->set_isa('WebGUI::Mail::Send');
$sendmock->set_true('addText', 'send', 'addHeaderField', 'addHtml', 'queue', 'addFooter');
local *WebGUI::Mail::Send::create;
$sendmock->fake_module('WebGUI::Mail::Send',
create => sub { return $sendmock },
);
#1234567890123456789012#
my $templateId = 'SHOP_NOTIFICATION_____';
my $templateMock = Test::MockObject->new({});
$templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $templateId);
my @templateVars;
$templateMock->mock('process', sub { push @templateVars, clone $_[1]; } );
$session->setting->set('shopReceiptEmailTemplateId', $templateId);
{
WebGUI::Test->mockAssetId($templateId, $templateMock);
$trans->sendNotifications;
is(@templateVars, 2, '... called template->process twice');
my $inbox = WebGUI::Inbox->new($session);
my $userMessages = $inbox->getMessagesForUser($shopUser);
my $adminMessages = $inbox->getMessagesForUser($shopAdmin);
is(@{ $userMessages }, 1, '... sent one message to shop user');
is(@{ $adminMessages }, 1, '... sent one message to shop admin, via shopSaleNotificationGroupId');
like($userMessages->[0]->get('subject'), qr/^Receipt for Order #/, '... subject for user email okay');
like($adminMessages->[0]->get('subject'), qr/^A sale has been made/, '... subject for admin email okay');
like($templateVars[0]->{viewDetailUrl}, qr/shop=transaction;method=viewMy;/, '... viewDetailUrl okay for user');
like($templateVars[1]->{viewDetailUrl}, qr/shop=transaction;method=view;/ , '... viewDetailUrl okay for admin');
WebGUI::Test->unmockAssetId($templateId);
}
#######################################################################
#
# delete
#
#######################################################################
$transaction->delete;
is($session->db->quickScalar("select transactionId from transaction where transactionId=?",[$transaction->getId]), undef, "can delete transactions");
is($session->db->quickScalar("select count(*) from transaction where transactionId=?",[$transaction->getId]),
0, "delete: deleted transaction");
is($session->db->quickScalar("select count(*) from transactionItem where transactionId=?",[$transaction->getId]),
0, "... deleted transactionItems associated with this transaction");
#----------------------------------------------------------------------------
# Cleanup
END {
$session->db->write('delete from transaction');
$session->db->write('delete from transactionItem');
}

View file

@ -100,16 +100,18 @@ sub import {
if ($ENV{WEBGUI_TEST_DEBUG}) {
##Offset Sessions, and Scratch by 1 because 1 will exist at the start
my @checkCount = (
Sessions => 'userSession',
Scratch => 'userSessionScratch',
Users => 'users',
Groups => 'groups',
mailQ => 'mailQueue',
Tags => 'assetVersionTag',
Assets => 'assetData',
Workflows => 'Workflow',
Carts => 'cart',
'Ship Drivers' => 'shipper',
Sessions => 'userSession',
Scratch => 'userSessionScratch',
Users => 'users',
Groups => 'groups',
mailQ => 'mailQueue',
Tags => 'assetVersionTag',
Assets => 'assetData',
Workflows => 'Workflow',
Carts => 'cart',
Transactions => 'transaction',
'Transaction Items' => 'transactionItem',
'Ship Drivers' => 'shipper',
);
my %initCounts;
for ( my $i = 0; $i < @checkCount; $i += 2) {
@ -767,6 +769,7 @@ were passed in. Currently able to destroy:
WebGUI::Workflow
WebGUI::Shop::Cart
WebGUI::Shop::ShipDriver
WebGUI::Shop::Transaction
Example call:
@ -835,14 +838,15 @@ Example call:
);
my %cleanup = (
'WebGUI::User' => 'delete',
'WebGUI::Group' => 'delete',
'WebGUI::Storage' => 'delete',
'WebGUI::Asset' => 'purge',
'WebGUI::VersionTag' => 'rollback',
'WebGUI::Workflow' => 'delete',
'WebGUI::Shop::ShipDriver' => 'delete',
'WebGUI::Shop::Cart' => sub {
'WebGUI::User' => 'delete',
'WebGUI::Group' => 'delete',
'WebGUI::Storage' => 'delete',
'WebGUI::Asset' => 'purge',
'WebGUI::VersionTag' => 'rollback',
'WebGUI::Workflow' => 'delete',
'WebGUI::Shop::Transaction' => 'delete',
'WebGUI::Shop::ShipDriver' => 'delete',
'WebGUI::Shop::Cart' => sub {
my $cart = shift;
my $addressBook = $cart->getAddressBook();
$addressBook->delete if $addressBook; ##Should we call cleanupGuard instead???