combine duplicate functions
authordemeritcowboy <demeritcowboy@hotmail.com>
Sat, 25 Jul 2020 15:41:35 +0000 (11:41 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Sat, 25 Jul 2020 15:41:35 +0000 (11:41 -0400)
tests/phpunit/CRM/Case/BAO/CaseTest.php
tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php
tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 57c2bc2935d1b926479276f0e6d7e4e331d05754..444d1c67c5f6ecfcf3828efd6d458c1c6109f3f9 100644 (file)
@@ -69,34 +69,6 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {
     $this->assertEquals('Test Contact - Housing Support', $recent[0]['title']);
   }
 
-  /**
-   * Create and return case object of given Client ID.
-   * @param $clientId
-   * @param $loggedInUser
-   * @return CRM_Case_BAO_Case
-   */
-  private function createCase($clientId, $loggedInUser = NULL) {
-    if (empty($loggedInUser)) {
-      // backwards compatibility - but it's more typical that the creator is a different person than the client
-      $loggedInUser = $clientId;
-    }
-    $caseParams = [
-      'activity_subject' => 'Case Subject',
-      'client_id'        => $clientId,
-      'case_type_id'     => 1,
-      'status_id'        => 1,
-      'case_type'        => 'housing_support',
-      'subject'          => 'Case Subject',
-      'start_date'       => date("Y-m-d"),
-      'start_date_time'  => date("YmdHis"),
-      'medium_id'        => 2,
-      'activity_details' => '',
-    ];
-    $form = new CRM_Case_Form_Case();
-    $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
-    return $caseObj;
-  }
-
   /**
    * Create case role relationship between given contacts for provided case ID.
    *
index 429ff9b60ecb1fd66d11d81d350962ca8d439e0e..def111e16a8fb2392914486c08dddce1325e6eaa 100644 (file)
@@ -289,35 +289,6 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
     }
   }
 
-  /**
-   * Create and return case object of given Client ID.
-   * @todo This is copy/paste from Case/BAO/CaseTest - should put into base class?
-   * @param $clientId
-   * @param $loggedInUser
-   * @return CRM_Case_BAO_Case
-   */
-  private function createCase($clientId, $loggedInUser = NULL) {
-    if (empty($loggedInUser)) {
-      // backwards compatibility - but it's more typical that the creator is a different person than the client
-      $loggedInUser = $clientId;
-    }
-    $caseParams = [
-      'activity_subject' => 'Case Subject',
-      'client_id'        => $clientId,
-      'case_type_id'     => 1,
-      'status_id'        => 1,
-      'case_type'        => 'housing_support',
-      'subject'          => 'Case Subject',
-      'start_date'       => date("Y-m-d"),
-      'start_date_time'  => date("YmdHis"),
-      'medium_id'        => 2,
-      'activity_details' => '',
-    ];
-    $form = new CRM_Case_Form_Case();
-    $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
-    return $caseObj;
-  }
-
   /**
    * Tests when the default assignee relationship exists, but in the other direction only.
    * Ana is a pupil, but has no pupils related to her.
index 3d1ce552568b689b5c9a4247e489c86ae7f20f4a..d524eecb495f17a92498f30c5d2730674b07c11d 100644 (file)
@@ -35,7 +35,7 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase {
       'prefix_id' => NULL,
       'suffix_id' => NULL,
     ]);
-    $caseObj = $this->createCase($client_id, $this->_loggedInUser);
+    $caseObj = $this->createCase($client_id, $this->_loggedInUser, ['start_date' => '2019-11-14', 'start_date_time' => '20191114000000']);
     $case_id = $caseObj->id;
 
     // Add an additional meeting activity not in the timeline to the case.
@@ -83,7 +83,7 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase {
       'prefix_id' => NULL,
       'suffix_id' => NULL,
     ]);
-    $caseObj = $this->createCase($client_id, $this->_loggedInUser);
+    $caseObj = $this->createCase($client_id, $this->_loggedInUser, ['start_date' => '2019-11-14', 'start_date_time' => '20191114000000']);
     $case_id = $caseObj->id;
 
     // Now update the timeline so it has Meeting in it.
@@ -554,30 +554,6 @@ class CRM_Case_XMLProcessor_ReportTest extends CiviCaseTestCase {
     }
   }
 
-  /**
-   * Create and return a new case object.
-   * @param $clientId
-   * @param $loggedInUser
-   * @return CRM_Case_BAO_Case
-   */
-  private function createCase($clientId, $loggedInUser) {
-    $caseParams = [
-      'activity_subject' => 'Case Subject',
-      'client_id'        => $clientId,
-      'case_type_id'     => $this->caseTypeId,
-      'status_id'        => 1,
-      'case_type'        => $this->caseType,
-      'subject'          => 'Case Subject',
-      'start_date'       => '2019-11-14',
-      'start_date_time'  => '20191114000000',
-      'medium_id'        => 2,
-      'activity_details' => '',
-    ];
-    $form = new CRM_Case_Form_Case();
-    $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
-    return $caseObj;
-  }
-
   /**
    * We don't need so many activities as in the stock case type. Just makes
    * dataprovider unnecessarily long. Just take the first two.
index 00ad21b303c8b703ff99582ac4b9c5a7838ed762..a200260d53d2a59d8ea50be03e89a7cc2956df06 100644 (file)
@@ -3596,4 +3596,37 @@ VALUES
     $this->assertEquals(0, $checkDeleted['count']);
   }
 
+  /**
+   * Create and return a case object for the given Client ID.
+   *
+   * @param int $clientId
+   * @param int $loggedInUser
+   *   Omit or pass NULL to use the same as clientId
+   * @param array $extra
+   *   Optional specific parameters such as start_date
+   *
+   * @return CRM_Case_BAO_Case
+   */
+  public function createCase($clientId, $loggedInUser = NULL, $extra = NULL) {
+    if (empty($loggedInUser)) {
+      // backwards compatibility - but it's more typical that the creator is a different person than the client
+      $loggedInUser = $clientId;
+    }
+    $caseParams = [
+      'activity_subject' => 'Case Subject',
+      'client_id'        => $clientId,
+      'case_type_id'     => 1,
+      'status_id'        => 1,
+      'case_type'        => 'housing_support',
+      'subject'          => 'Case Subject',
+      'start_date'       => ($extra['start_date'] ?? date("Y-m-d")),
+      'start_date_time'  => ($extra['start_date_time'] ?? date("YmdHis")),
+      'medium_id'        => 2,
+      'activity_details' => '',
+    ];
+    $form = new CRM_Case_Form_Case();
+    $caseObj = $form->testSubmit($caseParams, "OpenCase", $loggedInUser, "standalone");
+    return $caseObj;
+  }
+
 }