Add a method to return emails for Inbox notifications.
Method is driven by profile data and settings.
This commit is contained in:
parent
987269f3c3
commit
bc3b204d9b
2 changed files with 72 additions and 3 deletions
|
|
@ -503,6 +503,34 @@ sub getGroupIdsRecursive {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getInboxAddresses ( )
|
||||
|
||||
Return a string with addresses that the user wants to receive Inbox
|
||||
notifications. If the user does not want Inbox notifications, then
|
||||
the string will be empty.
|
||||
|
||||
=cut
|
||||
|
||||
sub getInboxAddresses {
|
||||
my $self = shift;
|
||||
my $emails = '';
|
||||
if ( $self->profileField('receiveInboxEmailNotifications')
|
||||
&& $self->profileField('email')) {
|
||||
$emails = $self->profileField('email');
|
||||
}
|
||||
if ( $self->profileField('receiveInboxSmsNotifications')
|
||||
&& $self->profileField('cellPhone')
|
||||
&& $self->session->setting->get('smsGateway')) {
|
||||
$emails .= ',' if $emails;
|
||||
my $phoneNumber = $self->profileField('cellPhone');
|
||||
$phoneNumber =~ tr/0-9//dc; ##remove nonnumbers
|
||||
$emails = join '', $emails, $phoneNumber, '@', $self->session->setting->get('smsGateway');
|
||||
}
|
||||
return $emails;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getProfileFieldPrivacySetting ( [field ])
|
||||
|
||||
Returns the privacy setting for the field passed in. If no field is passed in the entire hash is returned
|
||||
|
|
|
|||
47
t/User.t
47
t/User.t
|
|
@ -20,7 +20,7 @@ use WebGUI::Cache;
|
|||
use WebGUI::User;
|
||||
use WebGUI::ProfileField;
|
||||
|
||||
use Test::More tests => 143; # increment this value for each test you create
|
||||
use Test::More tests => 152; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
|
@ -620,7 +620,6 @@ cmp_bag(
|
|||
'getGroupIdsRecursive returns the correct set of groups, ignoring expire date and not duplicating groups'
|
||||
);
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test the new create() method
|
||||
SKIP: {
|
||||
|
|
@ -637,9 +636,49 @@ ok( my $newCreateUser = WebGUI::User->create( $session ),
|
|||
);
|
||||
isa_ok( $newCreateUser, 'WebGUI::User', 'create() returns a WebGUI::User' );
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getInboxAddresses
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $origSmsGateway = $session->setting->get('smsGateway');
|
||||
$session->setting->set('smsGateway', '');
|
||||
my $inmate = WebGUI::User->create($session);
|
||||
$inmate->profileField('email', '');
|
||||
$inmate->profileField('cellPhone', '');
|
||||
$inmate->profileField('receiveInboxEmailNotifications', 0);
|
||||
$inmate->profileField('receiveInboxSmsNotifications', 0);
|
||||
is ($inmate->getInboxAddresses, '', 'getInboxAddresses: with no profile info, returns blank');
|
||||
|
||||
$inmate->profileField('receiveInboxEmailNotifications', 1);
|
||||
is ($inmate->getInboxAddresses, '', 'getInboxAddresses: 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');
|
||||
|
||||
$inmate->profileField('receiveInboxSmsNotifications', 1);
|
||||
is ($inmate->getInboxAddresses, 'andy@shawshank.com', 'getInboxAddresses: 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');
|
||||
|
||||
$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');
|
||||
|
||||
END {
|
||||
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend, $newFish, $newCreateUser) {
|
||||
foreach my $account ($user, $dude, $buster, $buster3, $neighbor, $friend,
|
||||
$newFish, $newCreateUser, $inmate) {
|
||||
(defined $account and ref $account eq 'WebGUI::User') and $account->delete;
|
||||
}
|
||||
|
||||
|
|
@ -662,6 +701,8 @@ END {
|
|||
|
||||
$newProfileField->delete();
|
||||
|
||||
$session->setting->set('smsGateway', $origSmsGateway);
|
||||
|
||||
$testCache->flush;
|
||||
my $newNumberOfUsers = $session->db->quickScalar('select count(*) from users');
|
||||
my $newNumberOfGroups = $session->db->quickScalar('select count(*) from groups');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue