Share function for identical code
authoreileen <emcnaughton@wikimedia.org>
Mon, 22 Mar 2021 10:41:28 +0000 (23:41 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 22 Mar 2021 10:41:28 +0000 (23:41 +1300)
tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php

index 40a5ea14b81f793fd954a34aa38acf6946bd7b7a..6efa0146fc596cb8b4551c5cbacd7559c2a41cb6 100644 (file)
@@ -1007,16 +1007,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
    */
   public function testActivityDateTimeMatchRepeatableSchedule(): void {
     $this->createScheduleFromFixtures('sched_activity_1day_r');
-
-    $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
-    $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
-    $activity->save();
-
-    $source['contact_id'] = $contact['id'];
-    $source['activity_id'] = $activity->id;
-    $source['record_type_id'] = 2;
-    $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
-    $activityContact->save();
+    $this->createActivityAndContactFromFixtures();
 
     $this->assertCronRuns([
       [
@@ -1051,16 +1042,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
    */
   public function testActivityDateTimeMatchRepeatableScheduleOnAbsDate(): void {
     $this->createScheduleFromFixtures('sched_activity_1day_r_on_abs_date');
-
-    $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures['phone_call']);
-    $contact = $this->callAPISuccess('contact', 'create', $this->fixtures['contact']);
-    $activity->save();
-
-    $source['contact_id'] = $contact['id'];
-    $source['activity_id'] = $activity->id;
-    $source['record_type_id'] = 2;
-    $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
-    $activityContact->save();
+    $this->createActivityAndContactFromFixtures();
 
     $this->assertCronRuns([
       [
@@ -2529,4 +2511,23 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
     $this->fixtures[$fixture]['action_schedule_id'] = (int) $id;
   }
 
+  /**
+   * @param string $activityKey
+   * @param string $contactKey
+   *
+   * @throws \CRM_Core_Exception
+   */
+  protected function createActivityAndContactFromFixtures(string $activityKey = 'phone_call', string $contactKey = 'contact'): void {
+    $activity = $this->createTestObject('CRM_Activity_DAO_Activity', $this->fixtures[$activityKey]);
+    $contact = $this->callAPISuccess('contact', 'create', $this->fixtures[$contactKey]);
+    $activity->save();
+
+    $source = [];
+    $source['contact_id'] = $contact['id'];
+    $source['activity_id'] = $activity->id;
+    $source['record_type_id'] = 2;
+    $activityContact = $this->createTestObject('CRM_Activity_DAO_ActivityContact', $source);
+    $activityContact->save();
+  }
+
 }