From f8471e72ef8d578629ca8b2abefe40de79949992 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Thu, 24 Sep 2020 14:23:45 -0400 Subject: [PATCH] test for target contacts on Bulk Email for mailing in batches --- .../phpunit/api/v3/JobProcessMailingTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/phpunit/api/v3/JobProcessMailingTest.php b/tests/phpunit/api/v3/JobProcessMailingTest.php index c45c4c55c826..98e8438d2d29 100644 --- a/tests/phpunit/api/v3/JobProcessMailingTest.php +++ b/tests/phpunit/api/v3/JobProcessMailingTest.php @@ -470,6 +470,49 @@ public function testConcurrency($settings, $expectedTallies, $expectedTotal) { $this->assertEquals(0, $apiCalls->getRunningCount()); } + /** + * Check that the earlier iterations's activity targets on the recorded + * BulkEmail activity don't get wiped out by subsequent iterations when + * using batches. + */ + public function testBatchActivityTargets() { + $loggedInUserId = $this->createLoggedInUser(); + + \Civi::settings()->set('mailerBatchLimit', 2); + + // We have such small batches we need to lower this interval to get it + // to create the activity. + $old_sync_interval = \Civi::settings()->get('civimail_sync_interval'); + \Civi::settings()->set('civimail_sync_interval', 1); + + $this->createContactsInGroup(6, $this->_groupID); + $mailing = $this->callAPISuccess('mailing', 'create', $this->_params + ['scheduled_id' => $loggedInUserId]); + $this->callAPISuccess('job', 'process_mailing', []); + $bulkEmailActivity = $this->callAPISuccess('Activity', 'getsingle', [ + 'source_record_id' => $mailing['id'], + 'activity_type_id' => 'Bulk Email', + 'return' => ['target_contact_id'], + ]); + // After first batch, should have two targets + $this->assertCount(2, $bulkEmailActivity['target_contact_id']); + + // Because we're running in script mode need to reset this static + // to get it to process the other batches. + CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; + + $this->callAPISuccess('job', 'process_mailing', []); + $bulkEmailActivity = $this->callAPISuccess('Activity', 'getsingle', [ + 'source_record_id' => $mailing['id'], + 'activity_type_id' => 'Bulk Email', + 'return' => ['target_contact_id'], + ]); + // After second batch, should have four targets + $this->assertCount(4, $bulkEmailActivity['target_contact_id']); + + // restore setting + \Civi::settings()->set('civimail_sync_interval', $old_sync_interval); + } + /** * Create contacts in group. *