From b20e742813473110b39a3fe825c82bce574fdd5c Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Tue, 11 Oct 2016 22:17:57 +0100 Subject: [PATCH] CRM-19353 unit test for mailing dedupe --- tests/phpunit/api/v3/MailingTest.php | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index d1a6212331..7378b63acd 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -250,6 +250,53 @@ 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() { + // BEGIN SAMPLE DATA + $groupIDs['grp'] = $this->groupCreate(array('name' => 'Example group', 'title' => 'Example group')); + $contactIDs['include_me'] = $this->individualCreate(array( + 'email' => 'include.me@example.org', + 'first_name' => 'Includer', + 'last_name' => 'Person', + )); + $contactIDs['include_me_duplicate'] = $this->individualCreate(array( + 'email' => 'include.me@example.org', + 'first_name' => 'IncluderDuplicate', + 'last_name' => 'Person', + )); + $this->callAPISuccess('GroupContact', 'create', array( + 'group_id' => $groupIDs['grp'], + 'contact_id' => $contactIDs['include_me'], + )); + $this->callAPISuccess('GroupContact', 'create', array( + 'group_id' => $groupIDs['grp'], + 'contact_id' => $contactIDs['include_me_duplicate'], + )); + + $params = $this->_params; + $params['groups']['include'] = array($groupIDs['grp']); + $params['mailings']['include'] = array(); + $params['options']['force_rollback'] = 1; + $params['dedupe_email'] = 1; + $params['api.mailing_job.create'] = 1; + $params['api.MailingRecipients.get'] = array( + 'mailing_id' => '$value.id', + 'api.contact.getvalue' => array( + 'return' => 'display_name', + ), + 'api.email.getvalue' => array( + 'return' => 'email', + ), + ); + // END SAMPLE DATA + + $create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__); + + $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'])); + $this->assertEquals(array('include.me@example.org'), $previewEmails); + } + /** * */ -- 2.25.1