3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Mailing_BAO_MailingTest
31 class CRM_Mailing_BAO_MailingTest
extends CiviUnitTestCase
{
33 public function setUp() {
38 * Test CRM_Mailing_BAO_Mailing::getRecipients() on sms mode
40 public function testgetRecipients() {
41 // Tests for SMS bulk mailing recipients
42 // +CRM-21320 Ensure primary mobile number is selected over non-primary
45 $smartGroupParams = array(
46 'formValues' => array('contact_type' => array('IN' => array('Individual'))),
48 $group = $this->smartGroupCreate($smartGroupParams);
49 $sms_provider = $this->callAPISuccess('SmsProvider', 'create', array(
59 // Create Contact 1 and add in group
60 $contactID1 = $this->individualCreate(array(), 0);
61 $this->callAPISuccess('GroupContact', 'Create', array(
63 'contact_id' => $contactID1,
66 // Create contact 2 and add in group
67 $contactID2 = $this->individualCreate(array(), 1);
68 $this->callAPISuccess('GroupContact', 'Create', array(
70 'contact_id' => $contactID2,
73 $contactIDPhoneRecords = array(
75 'primary_phone_id' => CRM_Utils_Array
::value('id', $this->callAPISuccess('Phone', 'create', array(
76 'contact_id' => $contactID1,
78 'location_type_id' => "Home",
79 'phone_type_id' => "Mobile",
82 'other_phone_id' => CRM_Utils_Array
::value('id', $this->callAPISuccess('Phone', 'create', array(
83 'contact_id' => $contactID1,
85 'location_type_id' => "Work",
86 'phone_type_id' => "Mobile",
91 'primary_phone_id' => CRM_Utils_Array
::value('id', $this->callAPISuccess('Phone', 'create', array(
92 'contact_id' => $contactID2,
94 'location_type_id' => "Home",
95 'phone_type_id' => "Mobile",
98 'other_phone_id' => CRM_Utils_Array
::value('id', $this->callAPISuccess('Phone', 'create', array(
99 'contact_id' => $contactID2,
101 'location_type_id' => "Work",
102 'phone_type_id' => "Mobile",
108 // Prepare expected results
109 $checkPhoneIDs = array(
110 $contactID1 => $contactIDPhoneRecords[$contactID1]['primary_phone_id'],
111 $contactID2 => $contactIDPhoneRecords[$contactID2]['primary_phone_id'],
115 $mailing = $this->callAPISuccess('Mailing', 'create', array('sms_provider_id' => $sms_provider['id']));
116 $mailing_include_group = $this->callAPISuccess('MailingGroup', 'create', array(
117 'mailing_id' => $mailing['id'],
118 'group_type' => "Include",
119 'entity_table' => "civicrm_group",
120 'entity_id' => $group,
123 // Populate the recipients table (job id doesn't matter)
124 CRM_Mailing_BAO_Mailing
::getRecipients($mailing['id']);
127 $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailing['id']));
129 // Check the count is correct
130 $this->assertEquals(2, $recipients['count'], 'Check recipient count');
132 // Check we got the 'primary' mobile for both contacts
133 foreach ($recipients['values'] as $value) {
134 $this->assertEquals($value['phone_id'], $checkPhoneIDs[$value['contact_id']], 'Check correct phone number for contact ' . $value['contact_id']);
138 $this->deleteMailing($mailing['id']);
139 $this->callAPISuccess('SmsProvider', 'Delete', array('id' => $sms_provider['id']));
140 $this->groupDelete($group);
141 $this->contactDelete($contactID1);
142 $this->contactDelete($contactID2);