From bc3b204d9bc64f94c95eee4aad8e4fd1941b47dd Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 16 Mar 2009 11:17:58 -0700 Subject: [PATCH] Add a method to return emails for Inbox notifications. Method is driven by profile data and settings. --- lib/WebGUI/User.pm | 28 +++++++++++++++++++++++++++ t/User.t | 47 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 6181c5d0c..364d9d5c5 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -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 diff --git a/t/User.t b/t/User.t index 309f103a9..13f210fb5 100644 --- a/t/User.t +++ b/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');