Removed hardcoded activity status and used Activity create
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 3 Jul 2019 08:17:16 +0000 (09:17 +0100)
committerPradeep Nayak <pradpnayak@gmail.com>
Sun, 7 Jul 2019 10:25:50 +0000 (11:25 +0100)
Added unit test

Use unique subject for activity in test

CRM/Mailing/BAO/MailingJob.php
tests/phpunit/CRM/Mailing/MailingSystemTest.php

index f14eb00c7e263f9fa9f79337056dfbbde7a5e3c8..58b58e4170c3e8c7d64e3cf85451e1d6780ea1ca 100644 (file)
@@ -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;
       }
 
index 645dbf6c97f1f7770840baf664bca05eabf818eb..0b9193dfc137360be85868b4acd076e6b8991b5e 100644 (file)
@@ -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);
+  }
+
 }