mailing#60: Fix regression where multiple bulk recipient option isn't respected
authorJon Goldberg <jon@megaphonetech.com>
Tue, 7 Jan 2020 18:53:52 +0000 (13:53 -0500)
committerJon Goldberg <jon@megaphonetech.com>
Wed, 8 Jan 2020 22:20:36 +0000 (17:20 -0500)
test fixes

CRM/Mailing/BAO/Recipients.php
tests/phpunit/api/v3/JobProcessMailingTest.php

index d91cdb519a99eadb91dd828091cc6e2d06484324..5c60de45d170065ef82fd3b058e08d7485bdd41d 100644 (file)
@@ -64,7 +64,7 @@ WHERE  mailing_id = %1
       // if any email is marked on_hold =1 or contact is deceased after mailing is submitted
       // then it should be get skipped while preparing event_queue
       // event_queue list is prepared when mailing job gets started.
-      $additionalJoin = " INNER JOIN civicrm_email e ON (r.email_id = e.id AND e.on_hold = 0 AND e.is_primary = 1)
+      $additionalJoin = " INNER JOIN civicrm_email e ON (r.email_id = e.id AND e.on_hold = 0)
                           INNER JOIN civicrm_contact c on (c.id = r.contact_id AND c.is_deceased <> 1 AND c.do_not_email = 0 AND c.is_opt_out = 0)
 ";
     }
index 4334acecb8859d46cfcb4f0e991ac1e3d8f993b2..c45c4c55c8265e5ae00ad5335804e087e903ff3c 100644 (file)
@@ -127,6 +127,38 @@ class api_v3_JobProcessMailingTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * Test that "multiple bulk email recipients" setting is respected.
+   */
+  public function testMultipleBulkRecipients() {
+    Civi::settings()->add([
+      'civimail_multiple_bulk_emails' => 1,
+    ]);
+    $contactID = $this->individualCreate(['first_name' => 'test recipient']);
+    $email1 = $this->callAPISuccess('email', 'create', [
+      'contact_id' => $contactID,
+      'email' => 'mail1@example.org',
+      'is_bulkmail' => 1,
+    ]);
+    $email2 = $this->callAPISuccess('email', 'create', [
+      'contact_id' => $contactID,
+      'email' => 'mail2@example.org',
+      'is_bulkmail' => 1,
+    ]);
+    $this->callAPISuccess('group_contact', 'create', [
+      'contact_id' => $contactID,
+      'group_id' => $this->_groupID,
+      'status' => 'Added',
+    ]);
+    $mailing = $this->callAPISuccess('mailing', 'create', $this->_params);
+    $this->assertEquals(2, $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailing['id']])['count']);
+    $this->callAPISuccess('job', 'process_mailing', []);
+    $this->_mut->assertRecipients([['mail1@example.org'], ['mail2@example.org']]);
+    // Don't leave data lying around for other tests to screw up on.
+    $this->callAPISuccess('Email', 'delete', ['id' => $email1['id']]);
+    $this->callAPISuccess('Email', 'delete', ['id' => $email2['id']]);
+  }
+
   /**
    * Test pause and resume on Mailing.
    */