*/
class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
- public function setUp() {
+ public function setUp(): void {
parent::setUp();
$this->defaultAssigneeOptionsValues = [];
$this->process = new CRM_Case_XMLProcessor_Process();
}
- public function tearDown() {
+ public function tearDown(): void {
$this->deleteMoreRelationshipTypes();
parent::tearDown();
}
}
- /**
- * 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.
* unique for each entry in the dataprovider since want to test a given
* relationship type against multiple xml strings. It's not a test
* identifier, it's an array key to use to look up something.
- * @param $xmlString string
- * @param $expected array
+ * @param string $xmlString
+ * @param array $expected
* @param $dontcare array We're re-using the data provider for two tests and
* we don't care about those expected values.
*
* unique for each entry in the dataprovider since want to test a given
* relationship type against multiple xml strings. It's not a test
* identifier, it's an array key to use to look up something.
- * @param $xmlString string
+ * @param string $xmlString
* @param $dontcare array We're re-using the data provider for two tests and
* we don't care about those expected values.
- * @param $expected array
+ * @param array $expected
*
* @dataProvider xmlCaseRoleDataProvider
*/
];
}
+ /**
+ * Test XMLProcessor activityTypes()
+ */
+ public function testXmlProcessorActivityTypes() {
+ // First change an activity's label since we also test getting the labels.
+ // @todo Having a brain freeze or something - can't do this in one step?
+ $activity_type_id = $this->callApiSuccess('OptionValue', 'get', [
+ 'option_group_id' => 'activity_type',
+ 'name' => 'Medical evaluation',
+ ])['id'];
+ $this->callApiSuccess('OptionValue', 'create', [
+ 'id' => $activity_type_id,
+ 'label' => 'Medical evaluation changed',
+ ]);
+
+ $p = new CRM_Case_XMLProcessor_Process();
+ $xml = $p->retrieve('housing_support');
+
+ // Test getting the `name`s
+ $activityTypes = $p->activityTypes($xml->ActivityTypes, FALSE, FALSE, FALSE);
+ $this->assertEquals(
+ [
+ 13 => 'Open Case',
+ 55 => 'Medical evaluation',
+ 56 => 'Mental health evaluation',
+ 57 => 'Secure temporary housing',
+ 60 => 'Income and benefits stabilization',
+ 58 => 'Long-term housing plan',
+ 14 => 'Follow up',
+ 15 => 'Change Case Type',
+ 16 => 'Change Case Status',
+ 18 => 'Change Case Start Date',
+ 25 => 'Link Cases',
+ ],
+ $activityTypes
+ );
+
+ // While we're here and have the `name`s check the editable types in
+ // Settings.xml which is something that gets called reasonably often
+ // thru CRM_Case_XMLProcessor_Process::activityTypes().
+ $activityTypeValues = array_flip($activityTypes);
+ $xml = $p->retrieve('Settings');
+ $settings = $p->activityTypes($xml->ActivityTypes, FALSE, FALSE, 'edit');
+ $this->assertEquals(
+ [
+ 'edit' => [
+ 0 => $activityTypeValues['Change Case Status'],
+ 1 => $activityTypeValues['Change Case Start Date'],
+ ],
+ ],
+ $settings
+ );
+
+ // Now get `label`s
+ $xml = $p->retrieve('housing_support');
+ $activityTypes = $p->activityTypes($xml->ActivityTypes, FALSE, TRUE, FALSE);
+ $this->assertEquals(
+ [
+ 13 => 'Open Case',
+ 55 => 'Medical evaluation changed',
+ 56 => 'Mental health evaluation',
+ 57 => 'Secure temporary housing',
+ 60 => 'Income and benefits stabilization',
+ 58 => 'Long-term housing plan',
+ 14 => 'Follow up',
+ 15 => 'Change Case Type',
+ 16 => 'Change Case Status',
+ 18 => 'Change Case Start Date',
+ 25 => 'Link Cases',
+ ],
+ $activityTypes
+ );
+ }
+
}