3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CiviReportTestCase
31 class CiviCaseTestCase
extends CiviUnitTestCase
{
34 * @var string symbolic-name
38 protected $caseTypeId;
40 protected $caseStatusGroup;
42 protected $optionValues;
44 protected $_loggedInUser;
46 public function setUp() {
49 // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
50 //. Using XML was causing breakage as id numbers were changing over time
51 // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
52 // state where tests could run afterwards without re-loading.
53 $this->caseStatusGroup
= $this->callAPISuccess('option_group', 'get', array(
54 'name' => 'case_status',
55 'format.only_id' => 1,
57 $optionValues = array(
58 'Medical evaluation' => 'Medical evaluation',
59 'Mental health evaluation' => "Mental health evaluation",
60 'Secure temporary housing' => 'Secure temporary housing',
61 'Long-term housing plan' => 'Long-term housing plan',
62 'ADC referral' => 'ADC referral',
63 'Income and benefits stabilization' => 'Income and benefits stabilization',
65 foreach ($optionValues as $name => $label) {
66 $activityTypes = $this->callAPISuccess('option_value', 'Create', array(
67 'option_group_id' => 2,
73 $this->optionValues
[] = $activityTypes['id'];
76 // We used to be inconsistent about "HousingSupport" vs "housing_support".
77 // Now, the rule is simply: use the "name" from "civicrm_case_type.name".
78 $this->caseType
= 'housing_support';
79 $this->caseTypeId
= 1;
80 $this->tablesToTruncate
= array(
83 'civicrm_custom_group',
84 'civicrm_custom_field',
86 'civicrm_case_contact',
87 'civicrm_case_activity',
89 'civicrm_activity_contact',
91 'civicrm_relationship',
92 'civicrm_relationship_type',
96 $this->quickCleanup($this->tablesToTruncate
);
98 $this->loadAllFixtures();
100 // enable the default custom templates for the case type xml files
101 $this->customDirectories(array('template_path' => TRUE));
103 // case is not enabled by default
104 $enableResult = CRM_Core_BAO_ConfigSetting
::enableComponent('CiviCase');
105 $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__
);
107 /** @var $hooks \CRM_Utils_Hook_UnitTests */
108 $hooks = \CRM_Utils_Hook
::singleton();
109 $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
110 \CRM_Case_XMLRepository
::singleton(TRUE);
111 \CRM_Case_XMLProcessor
::flushStaticCaches();
113 // create a logged in USER since the code references it for source_contact_id
114 $this->createLoggedInUser();
115 $session = CRM_Core_Session
::singleton();
116 $this->_loggedInUser
= $session->get('userID');
117 /// note that activityType options are cached by the FULL set of options you pass in
118 // ie. because Activity api includes campaign in it's call cache is not flushed unless
119 // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
120 CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
124 * Tears down the fixture, for example, closes a network connection.
125 * This method is called after a test is executed.
127 public function tearDown() {
128 $this->quickCleanup($this->tablesToTruncate
, TRUE);
129 $this->customDirectories(array('template_path' => FALSE));
130 CRM_Case_XMLRepository
::singleton(TRUE);
134 * Subclasses may override this if they want to be explicit about the case-type definition.
137 * @see CRM_Utils_Hook::caseTypes
139 public function hook_caseTypes(&$caseTypes) {