replace call to function that doesn't cache properly
authordemeritcowboy <demeritcowboy@hotmail.com>
Sun, 14 Jun 2020 21:45:10 +0000 (17:45 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Sun, 14 Jun 2020 21:45:10 +0000 (17:45 -0400)
CRM/Case/XMLProcessor/Process.php
tests/phpunit/CRM/Case/XMLProcessor/ProcessTest.php

index 9307f2bb905a61f408e0121b175186bcd3200943..d1f63c975b57727ec522185399db8b5b44cfbf0f 100644 (file)
@@ -253,7 +253,7 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor {
    * @return array
    */
   public function activityTypes($activityTypesXML, $maxInst = FALSE, $isLabel = FALSE, $maskAction = FALSE) {
-    $activityTypes = &$this->allActivityTypes(TRUE, TRUE);
+    $activityTypes = CRM_Case_PseudoConstant::caseActivityType(TRUE, TRUE);
     $result = [];
     foreach ($activityTypesXML as $activityTypeXML) {
       foreach ($activityTypeXML as $recordXML) {
index db7144d5920a491c0b1af2d812ccbf314ee9eb44..bc24f4c670c6113c20b4a761e597b4551f44ea90 100644 (file)
@@ -427,4 +427,78 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
     ];
   }
 
+  /**
+   * 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
+    );
+  }
+
 }