From 7580050cf74fe3b6a8389ab1846d38131c5ec5cd Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Sat, 25 Jul 2020 11:41:35 -0400 Subject: [PATCH] combine duplicate functions --- tests/phpunit/CRM/Case/BAO/CaseTest.php | 28 ---------------- .../CRM/Case/XMLProcessor/ProcessTest.php | 29 ---------------- .../CRM/Case/XMLProcessor/ReportTest.php | 28 ++-------------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 33 +++++++++++++++++++ 4 files changed, 35 insertions(+), 83 deletions(-) diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 57c2bc2935..444d1c67c5 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -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. * diff --git a/tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php b/tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php index 429ff9b60e..def111e16a 100644 --- a/tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php +++ b/tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php @@ -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. diff --git a/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php b/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php index 3d1ce55256..d524eecb49 100644 --- a/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php +++ b/tests/phpunit/CRM/Case/XMLProcessor/ReportTest.php @@ -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. diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 00ad21b303..a200260d53 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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; + } + } -- 2.25.1