Fixed a whole lot of brokenness in Inbox SMS/Email notifications

WebGUI::Inbox::Message::create now passes isInbox flag to WebGUI::Mail::Send::create
so that per-user notification settings get used

SMS Gateway setting field is now 'text' instead of 'email' so that user can enter a
properly formed value (such as 'myemailgateway.com', which is not an email address).

Added SMS notification template as distinct from email notification template because
SMSs should not be HTML and in general you will want to make your SMS notification
message a lot shorter than your html email notification message (160 char limits in
many countries). As a result, SMSs are now sent as separate emails to gateway rather
than being CCd on email notification.

Added smsGatewaySubject setting because many SMS Gateways use email subject for
authentication. For consistency, also added Email notification email subject.

Fixed handling of different combinations of site-wide sendInboxNotificationsOnly with
per-user receiveInboxEmailNotifications and receiveInboxSmsEmailNotifications.
 * sendInboxNotificationsOnly && receiveInboxEmailNotifications = email notification
 * sendInboxNotificationsOnly && !receiveInboxEmailNotifications = no email
 * !sendInboxNotificationsOnly = ignore receiveInboxEmailNotifications
 * In all cases, SMS is optional and only dependent on receiveInboxSmsEmailNotifications

Updated tests and i18n
This commit is contained in:
Patrick Donelan 2009-08-16 09:42:35 +00:00
parent 3cc02af6bb
commit 388a0b1267
12 changed files with 264 additions and 109 deletions

View file

@ -42,7 +42,7 @@ if ( $@ ) { diag( "Can't prepare mail server: $@" ) }
#----------------------------------------------------------------------------
# Tests
plan tests => 18; # Increment this number for each test you create
plan tests => 16; # Increment this number for each test you create
#----------------------------------------------------------------------------
# Test create
@ -274,7 +274,6 @@ $emailUser->profileField('email', 'heywood@shawshank.gov');
my $lonelyUser = WebGUI::User->create($session);
WebGUI::Test->usersToDelete($lonelyUser);
$lonelyUser->profileField('receiveInboxEmailNotifications', 0);
$lonelyUser->profileField('receiveInboxSmsNotifications', 0);
$lonelyUser->profileField('email', 'jake@shawshank.gov');
my $inboxGroup = WebGUI::Group->new($session, 'new');
@ -300,45 +299,6 @@ SKIP: {
# Test the mail
is($received->{to}->[0], '<ellis_boyd_redding@shawshank.gov>', 'send, toUser with email address');
$inboxUser->profileField('receiveInboxEmailNotifications', 0);
$inboxUser->profileField('receiveInboxSmsNotifications', 1);
# Send the mail
$mail = WebGUI::Mail::Send->create( $session, {
toUser => $inboxUser->userId,
},
'fromInbox',
);
$mail->addText( 'sent via SMS' );
$mail->send;
my $received = WebGUI::Test->getMail;
# Test the mail
is($received->{to}->[0], '<55555@textme.com>', 'send, toUser with SMS address');
$inboxUser->profileField('receiveInboxEmailNotifications', 1);
$inboxUser->profileField('receiveInboxSmsNotifications', 1);
# Send the mail
$mail = WebGUI::Mail::Send->create( $session, {
toUser => $inboxUser->userId,
},
'fromInbox',
);
$mail->addText( 'sent via SMS' );
$mail->send;
my $received = WebGUI::Test->getMail;
# Test the mail
cmp_bag(
$received->{to},
['<55555@textme.com>', '<ellis_boyd_redding@shawshank.gov>',],
'send, toUser with SMS and email addresses'
);
}
#----------------------------------------------------------------------------
@ -377,7 +337,7 @@ cmp_bag(
\@emailAddresses,
[
'heywood@shawshank.gov'."\n",
'ellis_boyd_redding@shawshank.gov,55555@textme.com'."\n",
'ellis_boyd_redding@shawshank.gov'."\n",
],
'send: when the original is sent, new messages are created for each user in the group, following their user profile settings'
);

View file

@ -22,7 +22,7 @@ use WebGUI::User;
use WebGUI::ProfileField;
use WebGUI::Shop::AddressBook;
use Test::More tests => 224; # increment this value for each test you create
use Test::More tests => 221; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
@ -970,7 +970,7 @@ $friend->deleteFromGroups([$neighbor->friends->getId]);
################################################################
#
# getInboxAddresses
# getInboxNotificationAddresses
#
################################################################
@ -982,32 +982,23 @@ $inmate->profileField('email', '');
$inmate->profileField('cellPhone', '');
$inmate->profileField('receiveInboxEmailNotifications', 0);
$inmate->profileField('receiveInboxSmsNotifications', 0);
is ($inmate->getInboxAddresses, '', 'getInboxAddresses: with no profile info, returns blank');
is ($inmate->getInboxNotificationAddresses, '', 'getInboxNotificationAddresses: with no profile info, returns blank');
$inmate->profileField('receiveInboxEmailNotifications', 1);
is ($inmate->getInboxAddresses, '', 'getInboxAddresses: with receiveInboxEmailNotifications=1, but not email address, returns blank');
is ($inmate->getInboxNotificationAddresses, '', 'getInboxNotificationAddresses: with receiveInboxEmailNotifications=1, but not email address, returns blank');
$inmate->profileField('email', 'andy@shawshank.com');
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: email address only');
is ($inmate->getInboxNotificationAddresses, 'andy@shawshank.com', 'getInboxNotificationAddresses: email address only');
$inmate->profileField('receiveInboxSmsNotifications', 1);
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 but no other profile info');
is ($inmate->getInboxNotificationAddresses, 'andy@shawshank.com', 'getInboxNotificationAddresses: receive only email address, with receiveInboSMSNotifications=1 but no other profile info');
$inmate->profileField('cellPhone', '37927');
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and cell phone but no gateway');
is ($inmate->getInboxNotificationAddresses, 'andy@shawshank.com', 'getInboxNotificationAddresses: receive only email address, with receiveInboSMSNotifications=1 and cell phone but no gateway');
$inmate->profileField('cellPhone', '');
$session->setting->set('smsGateway', 'textme.com');
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone');
$inmate->profileField('cellPhone', '37927');
is ($inmate->getInboxAddresses, 'andy@shawshank.com,37927@textme.com', 'getInboxAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone');
$inmate->profileField('receiveInboxEmailNotifications', 0);
is ($inmate->getInboxAddresses, '37927@textme.com', 'getInboxAddresses: can get SMS and no email, even with email info present');
$inmate->profileField('receiveInboxSmsNotifications', 0);
is ($inmate->getInboxAddresses, '', 'getInboxAddresses: can get no SMS and no email, even with profile info present');
is ($inmate->getInboxNotificationAddresses, 'andy@shawshank.com', 'getInboxNotificationAddresses: receive only email address, with receiveInboSMSNotifications=1 and gateway but no cell phone');
################################################################
#