From a668270fdcc3fa2aa11ea5ec6802199fb8323371 Mon Sep 17 00:00:00 2001 From: dl617 Date: Tue, 2 Oct 2018 13:09:07 +0100 Subject: [PATCH] core/384 failing test for mobile phone type --- tests/phpunit/CRM/Mailing/BAO/MailingTest.php | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php index 4d3d77d2b9..51685a063b 100644 --- a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -413,6 +413,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { public function testgetRecipientsSMS() { // Tests for SMS bulk mailing recipients // +CRM-21320 Ensure primary mobile number is selected over non-primary + // +CUDARW-905 Ensure that a secondary mobile number is selected if the primary can not receive SMS // Setup $smartGroupParams = array( @@ -443,6 +444,13 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { '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( @@ -477,12 +485,30 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'is_primary' => 1, ))), ), + // Create primary that cant recieve SMS but a secondary that can, to test CUDARW-905 + $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'], ); // Create mailing @@ -494,9 +520,9 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { $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']); } @@ -507,6 +533,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { $this->groupDelete($group); $this->contactDelete($contactID1); $this->contactDelete($contactID2); + $this->contactDelete($contactID3); } /** -- 2.25.1