Unverified Commit ed760322 authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #11848 from jitendrapurohit/CRM-21848-test

CRM-21848 - Add unit test for on_hold mailing recipients
parents e83b3ac0 2008d65d
......@@ -328,7 +328,10 @@ class api_v3_MailingTest extends CiviUnitTestCase {
$this->assertTrue((bool) preg_match('/Includer Person/', $previewNames[0]), "Name 'Includer Person' should appear in '" . $previewNames[0] . '"');
}
public function testMailerPreviewRecipientsDeduplicate() {
/**
* Test if Mailing recipients include duplicate OR on_hold emails
*/
public function testMailerPreviewRecipientsDeduplicateAndOnholdEmails() {
// BEGIN SAMPLE DATA
$groupIDs['grp'] = $this->groupCreate(array('name' => 'Example group', 'title' => 'Example group'));
$contactIDs['include_me'] = $this->individualCreate(array(
......@@ -341,6 +344,21 @@ class api_v3_MailingTest extends CiviUnitTestCase {
'first_name' => 'IncluderDuplicate',
'last_name' => 'Person',
));
$contactIDs['include_me_onhold'] = $this->individualCreate(array(
'email' => 'onholdinclude.me@example.org',
'first_name' => 'Onhold',
'last_name' => 'Person',
));
$emailId = $this->callAPISuccessGetValue('Email', array(
'return' => 'id',
'contact_id' => $contactIDs['include_me_onhold'],
));
$this->callAPISuccess('Email', 'create', array(
'id' => $emailId,
'on_hold' => TRUE,
));
$this->callAPISuccess('GroupContact', 'create', array(
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me'],
......@@ -349,6 +367,10 @@ class api_v3_MailingTest extends CiviUnitTestCase {
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me_duplicate'],
));
$this->callAPISuccess('GroupContact', 'create', array(
'group_id' => $groupIDs['grp'],
'contact_id' => $contactIDs['include_me_onhold'],
));
$params = $this->_params;
$params['groups']['include'] = array($groupIDs['grp']);
......@@ -368,6 +390,7 @@ class api_v3_MailingTest extends CiviUnitTestCase {
$create = $this->callAPISuccess('Mailing', 'create', $params);
//Recipient should not contain duplicate or on_hold emails.
$preview = $create['values'][$create['id']]['api.MailingRecipients.get'];
$this->assertEquals(1, $preview['count']);
$previewEmails = array_values(CRM_Utils_Array::collect('api.email.getvalue', $preview['values']));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment