3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CiviReportTestCase
15 class CiviCaseTestCase
extends CiviUnitTestCase
{
18 * @var string symbolic-name
22 protected $caseTypeId;
24 protected $caseStatusGroup;
26 protected $optionValues;
28 protected $_loggedInUser;
30 public function setUp() {
33 // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
34 //. Using XML was causing breakage as id numbers were changing over time
35 // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
36 // state where tests could run afterwards without re-loading.
37 $this->caseStatusGroup
= $this->callAPISuccess('option_group', 'get', array(
38 'name' => 'case_status',
39 'format.only_id' => 1,
41 $optionValues = array(
42 'Medical evaluation' => 'Medical evaluation',
43 'Mental health evaluation' => "Mental health evaluation",
44 'Secure temporary housing' => 'Secure temporary housing',
45 'Long-term housing plan' => 'Long-term housing plan',
46 'ADC referral' => 'ADC referral',
47 'Income and benefits stabilization' => 'Income and benefits stabilization',
49 foreach ($optionValues as $name => $label) {
50 $activityTypes = $this->callAPISuccess('option_value', 'Create', array(
51 'option_group_id' => 2,
57 $this->optionValues
[] = $activityTypes['id'];
60 // We used to be inconsistent about "HousingSupport" vs "housing_support".
61 // Now, the rule is simply: use the "name" from "civicrm_case_type.name".
62 $this->caseType
= 'housing_support';
63 $this->caseTypeId
= 1;
64 $this->tablesToTruncate
= array(
67 'civicrm_custom_group',
68 'civicrm_custom_field',
70 'civicrm_case_contact',
71 'civicrm_case_activity',
73 'civicrm_activity_contact',
75 'civicrm_relationship',
76 'civicrm_relationship_type',
80 $this->quickCleanup($this->tablesToTruncate
);
82 $this->loadAllFixtures();
84 // enable the default custom templates for the case type xml files
85 $this->customDirectories(array('template_path' => TRUE));
87 // case is not enabled by default
88 $enableResult = CRM_Core_BAO_ConfigSetting
::enableComponent('CiviCase');
89 $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__
);
91 /** @var $hooks \CRM_Utils_Hook_UnitTests */
92 $hooks = \CRM_Utils_Hook
::singleton();
93 $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
94 \CRM_Case_XMLRepository
::singleton(TRUE);
95 \CRM_Case_XMLProcessor
::flushStaticCaches();
97 // create a logged in USER since the code references it for source_contact_id
98 $this->createLoggedInUser();
99 $session = CRM_Core_Session
::singleton();
100 $this->_loggedInUser
= $session->get('userID');
101 /// note that activityType options are cached by the FULL set of options you pass in
102 // ie. because Activity api includes campaign in it's call cache is not flushed unless
103 // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
104 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
108 * Tears down the fixture, for example, closes a network connection.
109 * This method is called after a test is executed.
111 public function tearDown() {
112 $this->quickCleanup($this->tablesToTruncate
, TRUE);
113 $this->customDirectories(array('template_path' => FALSE));
114 CRM_Case_XMLRepository
::singleton(TRUE);
118 * Subclasses may override this if they want to be explicit about the case-type definition.
121 * @see CRM_Utils_Hook::caseTypes
123 public function hook_caseTypes(&$caseTypes) {