Skip to content

Commit

Permalink
Merge pull request #11848 from jitendrapurohit/CRM-21848-test
Browse files Browse the repository at this point in the history
CRM-21848 - Add unit test for on_hold mailing recipients
  • Loading branch information
eileenmcnaughton authored Mar 21, 2018
2 parents e83b3ac + 2008d65 commit ed76032
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/phpunit/api/v3/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ public function testMailerPreviewRecipients() {
$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(
Expand All @@ -341,6 +344,21 @@ public function testMailerPreviewRecipientsDeduplicate() {
'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'],
Expand All @@ -349,6 +367,10 @@ public function testMailerPreviewRecipientsDeduplicate() {
'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']);
Expand All @@ -368,6 +390,7 @@ public function testMailerPreviewRecipientsDeduplicate() {

$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']));
Expand Down

0 comments on commit ed76032

Please sign in to comment.