Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/384 CiviSMS does not fall back to non-primary mobile number #12890

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public static function getRecipients($mailingID) {
'location_filter' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.phone_type_id = " . CRM_Core_PseudoConstant::getKey('CRM_Core_DAO_Phone', 'phone_type_id', 'Mobile')),
'phone_not_null' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.phone IS NOT NULL"),
'phone_not_empty' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.phone != ''"),
'is_primary' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.is_primary = 1"),
'mailing_id' => CRM_Utils_SQL_Select::fragment()->where("mg.mailing_id = #mailingID"),
'temp_contact_null' => CRM_Utils_SQL_Select::fragment()->where('temp.contact_id IS null'),
'order_by' => CRM_Utils_SQL_Select::fragment()->orderBy("$entityTable.is_primary = 1"),
Expand Down
31 changes: 29 additions & 2 deletions tests/phpunit/CRM/Mailing/BAO/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public function testgetRecipientsEmailGroupIncludeExclude() {
public function testgetRecipientsSMS() {
// Tests for SMS bulk mailing recipients
// +CRM-21320 Ensure primary mobile number is selected over non-primary
// +core/384 Ensure that a secondary mobile number is selected if the primary can not receive SMS

// Setup
$smartGroupParams = array(
Expand Down Expand Up @@ -443,6 +444,13 @@ public function testgetRecipientsSMS() {
'contact_id' => $contactID2,
));

// Create contact 3 and add in group
$contactID3 = $this->individualCreate(array(), 2);
$this->callAPISuccess('GroupContact', 'Create', array(
'group_id' => $group,
'contact_id' => $contactID3,
));

$contactIDPhoneRecords = array(
$contactID1 => array(
'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
Expand Down Expand Up @@ -477,12 +485,30 @@ public function testgetRecipientsSMS() {
'is_primary' => 1,
))),
),
// Create primary that cant recieve SMS but a secondary that can, to test core/384
$contactID3 => array(
'other_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
'contact_id' => $contactID3,
'phone' => "03 01",
'location_type_id' => "Home",
'phone_type_id' => "Mobile",
'is_primary' => 0,
))),
'primary_phone_id' => CRM_Utils_Array::value('id', $this->callAPISuccess('Phone', 'create', array(
'contact_id' => $contactID3,
'phone' => "03 02",
'location_type_id' => "Work",
'phone_type_id' => "Phone",
'is_primary' => 1,
))),
),
);

// Prepare expected results
$checkPhoneIDs = array(
$contactID1 => $contactIDPhoneRecords[$contactID1]['primary_phone_id'],
$contactID2 => $contactIDPhoneRecords[$contactID2]['primary_phone_id'],
$contactID3 => $contactIDPhoneRecords[$contactID3]['other_phone_id'],
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JKingsnorth is this line wrong? ie if we fix order by it will be the primary phone id?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton - no this test is correct, we want to pick up the 'other' in this case, because the primary phone number is not of the type 'mobile'.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhhh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More like 'aaarrghh?!'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

);

// Create mailing
Expand All @@ -494,9 +520,9 @@ public function testgetRecipientsSMS() {
$recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailing['id']));

// Check the count is correct
$this->assertEquals(2, $recipients['count'], 'Check recipient count');
$this->assertEquals(3, $recipients['count'], 'Check recipient count');

// Check we got the 'primary' mobile for both contacts
// Check we got the 'primary' mobile for contacts or the other phone when the primary was no SMS capable.
foreach ($recipients['values'] as $value) {
$this->assertEquals($value['phone_id'], $checkPhoneIDs[$value['contact_id']], 'Check correct phone number for contact ' . $value['contact_id']);
}
Expand All @@ -507,6 +533,7 @@ public function testgetRecipientsSMS() {
$this->groupDelete($group);
$this->contactDelete($contactID1);
$this->contactDelete($contactID2);
$this->contactDelete($contactID3);
}

/**
Expand Down