From 28106149cdcea2af4a0ce2256d16567880fa9891 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 3 Jul 2019 09:17:16 +0100 Subject: [PATCH] Removed hardcoded activity status and used Activity create Added unit test Use unique subject for activity in test --- CRM/Mailing/BAO/MailingJob.php | 7 +++++-- .../phpunit/CRM/Mailing/MailingSystemTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index f14eb00c7e..58b58e4170 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -1001,7 +1001,7 @@ AND status IN ( 'Scheduled', 'Running', 'Paused' ) 'source_record_id' => $this->mailing_id, 'activity_date_time' => $job_date, 'subject' => $mailing->subject, - 'status_id' => 2, + 'status_id' => 'Completed', 'deleteActivityTarget' => FALSE, 'campaign_id' => $mailing->campaign_id, ]; @@ -1048,7 +1048,10 @@ AND record_type_id = $targetRecordID } } - if (is_a(CRM_Activity_BAO_Activity::create($activity), 'CRM_Core_Error')) { + try { + civicrm_api3('Activity', 'create', $activity); + } + catch (Exception $e) { $result = FALSE; } diff --git a/tests/phpunit/CRM/Mailing/MailingSystemTest.php b/tests/phpunit/CRM/Mailing/MailingSystemTest.php index 645dbf6c97..0b9193dfc1 100644 --- a/tests/phpunit/CRM/Mailing/MailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/MailingSystemTest.php @@ -111,4 +111,23 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest { parent::testHtmlWithOpenAndUrlTracking(); } + /** + * Test to check Activity being created on mailing Job. + * + */ + public function testMailingActivityCreate() { + $subject = uniqid('testMailingActivityCreate'); + $this->runMailingSuccess([ + 'subject' => $subject, + 'body_html' => 'Test Mailing Activity Create', + 'scheduled_id' => $this->individualCreate(), + ]); + + $this->callAPISuccessGetCount('activity', [ + 'activity_type_id' => 'Bulk Email', + 'status_id' => 'Completed', + 'subject' => $subject, + ], 1); + } + } -- 2.25.1