From: deb.monish Date: Fri, 30 Mar 2018 17:48:33 +0000 (+0530) Subject: extend unit test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=be2c9578b202ac5835e29ae5dee64f3b85d6b068;p=civicrm-core.git extend unit test --- diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 1f7965fb41..f306c72770 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -228,7 +228,6 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing { ); if ($isSMSmode) { - $criteria = array( 'is_opt_out' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_opt_out = 0"), 'is_deceased' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_deceased <> 1"), @@ -250,6 +249,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing { 'location_filter' => CRM_Utils_SQL_Select::fragment()->where($location_filter), 'email_not_null' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.email IS NOT NULL"), 'email_not_empty' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.email != ''"), + 'email_not_on_hold' => CRM_Utils_SQL_Select::fragment()->where("$entityTable.on_hold = 0"), 'mailing_id' => CRM_Utils_SQL_Select::fragment()->where("mg.mailing_id = #mailingID"), 'temp_contact_null' => CRM_Utils_SQL_Select::fragment()->where('temp.contact_id IS NULL'), 'order_by' => CRM_Utils_SQL_Select::fragment()->orderBy($order_by), diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php index 09a0044326..5e999c45e8 100644 --- a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -463,11 +463,15 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { */ public function testAlterMailingRecipientsHook() { $groupID = $this->groupCreate(); + $this->tagCreate(array('name' => 'Tagged')); // Create deseased Contact 1 and add in group $contactID1 = $this->individualCreate(array('email' => 'abc@test.com', 'is_deceased' => 1), 0); // Create deseased Contact 2 and add in group $contactID2 = $this->individualCreate(array('email' => 'def@test.com'), 1); + // Create deseased Contact 3 and add in group + $contactID3 = $this->individualCreate(array('email' => 'ghi@test.com', 'is_deceased' => 1), 2); + // Add both the created contacts in group $this->callAPISuccess('GroupContact', 'Create', array( 'group_id' => $groupID, @@ -477,6 +481,12 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { 'group_id' => $groupID, 'contact_id' => $contactID2, )); + $this->callAPISuccess('GroupContact', 'Create', array( + 'group_id' => $groupID, + 'contact_id' => $contactID3, + )); + $this->entityTagAdd(array('contact_id' => $contactID3, 'tag_id' => 'Tagged')); + // trigger the alterMailingRecipients hook $this->hookClass->setHook('civicrm_alterMailingRecipients', array($this, 'alterMailingRecipients')); @@ -497,13 +507,17 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { * @implements CRM_Utils_Hook::alterMailingRecipients * * @param object $mailingObject - * @param array $params + * @param array $criteria * @param string $context */ - public function alterMailingRecipients(&$mailingObject, &$params, $context) { + public function alterMailingRecipients(&$mailingObject, &$criteria, $context) { if ($context == 'pre') { - // modify the filter to include only deceased recipient(s) - $params['filters']['is_deceased'] = 'civicrm_contact.is_deceased = 1'; + // modify the filter to include only deceased recipient(s) that is Tagged + $criteria['is_deceased'] = CRM_Utils_SQL_Select::fragment()->where("civicrm_contact.is_deceased = 1"); + $criteria['tagged_contact'] = CRM_Utils_SQL_Select::fragment() + ->join('civicrm_entity_tag', "INNER JOIN civicrm_entity_tag et ON et.entity_id = civicrm_contact.id AND et.entity_table = 'civicrm_contact'") + ->join('civicrm_tag', "INNER JOIN civicrm_tag t ON t.id = et.tag_id") + ->where("t.name = 'Tagged'"); } else { $mailingRecipients = $this->callAPISuccess('MailingRecipients', 'get', array( @@ -514,7 +528,7 @@ class CRM_Mailing_BAO_MailingTest extends CiviUnitTestCase { ), )); $this->assertEquals(1, $mailingRecipients['count'], 'Check recipient count'); - $this->assertEquals('abc@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact'); + $this->assertEquals('ghi@test.com', $mailingRecipients['values'][$mailingRecipients['id']]['api.Email.getvalue'], 'Check if recipient email belong to deceased contact'); } }