Additional unit test
authorJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 4 Jun 2018 05:16:20 +0000 (10:46 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Mon, 4 Jun 2018 05:16:20 +0000 (10:46 +0530)
tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php

index f169fa0b8407d2e0529ef66d703f346211674001..fa0f43d80c411d64b6d1ffe39563bd5005cd4dc6 100644 (file)
@@ -1699,7 +1699,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
       'return' => "id",
       'name' => "Attended",
     ));
-    $this->callAPISuccess('action_schedule', 'create', $actionSchedule);
+    $actionSched = $this->callAPISuccess('action_schedule', 'create', $actionSchedule);
     //Run the cron and verify if an email was sent.
     $this->assertCronRuns(array(
       array(
@@ -1707,6 +1707,40 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
         'recipients' => array(array('test-event@example.com')),
       ),
     ));
+
+    //Create contact 2
+    $contactParams = array(
+      'email' => 'test-event2@example.com',
+    );
+    $contact2 = $this->individualCreate($contactParams);
+    //Create an event with registration end date = 2 week from now.
+    $params['end_date'] = date('Ymd', strtotime('+2 week'));
+    $params['registration_end_date'] = date('Ymd', strtotime('+2 week'));
+    $event2 = $this->eventCreate($params);
+    $this->participantCreate(array('contact_id' => $contact2, 'event_id' => $event2['id']));
+
+    //Assert there is no reminder sent to the contact.
+    $this->assertCronRuns(array(
+      array(
+        'time' => date('Y-m-d'),
+        'recipients' => array(),
+      ),
+    ));
+
+    //Modify the sched reminder to be sent 2 week from registration end date.
+    $this->callAPISuccess('action_schedule', 'create', array(
+      'id' => $actionSched['id'],
+      'start_action_offset' => 2,
+      'start_action_unit' => 'week',
+    ));
+
+    //Contact should receive the reminder now.
+    $this->assertCronRuns(array(
+      array(
+        'time' => date('Y-m-d'),
+        'recipients' => array(array('test-event2@example.com')),
+      ),
+    ));
   }
 
   /**