Commit | Line | Data |
---|---|---|
1d8a8d12 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
1d8a8d12 | 5 | | | |
7d61e75f TO |
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 | | |
1d8a8d12 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
1d8a8d12 | 11 | |
1d8a8d12 TO |
12 | /** |
13 | * Class CiviReportTestCase | |
14 | */ | |
15 | class CiviCaseTestCase extends CiviUnitTestCase { | |
16 | ||
bb68492c | 17 | /** |
1d3260ea SL |
18 | * @var string |
19 | * Symbolic-name | |
bb68492c TO |
20 | */ |
21 | protected $caseType; | |
22 | ||
1d8a8d12 | 23 | protected $caseTypeId; |
bb68492c | 24 | |
1d8a8d12 | 25 | protected $caseStatusGroup; |
bb68492c | 26 | |
1d8a8d12 | 27 | protected $optionValues; |
bb68492c | 28 | |
1d8a8d12 TO |
29 | protected $_loggedInUser; |
30 | ||
5d345864 | 31 | public function setUp(): void { |
1d8a8d12 | 32 | parent::setUp(); |
bb68492c | 33 | |
1d8a8d12 TO |
34 | // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types |
35 | //. Using XML was causing breakage as id numbers were changing over time | |
36 | // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a | |
37 | // state where tests could run afterwards without re-loading. | |
38 | $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array( | |
39b959db SL |
39 | 'name' => 'case_status', |
40 | 'format.only_id' => 1, | |
41 | )); | |
0ca4b209 | 42 | $optionValues = [ |
1d8a8d12 TO |
43 | 'Medical evaluation' => 'Medical evaluation', |
44 | 'Mental health evaluation' => "Mental health evaluation", | |
45 | 'Secure temporary housing' => 'Secure temporary housing', | |
46 | 'Long-term housing plan' => 'Long-term housing plan', | |
47 | 'ADC referral' => 'ADC referral', | |
48 | 'Income and benefits stabilization' => 'Income and benefits stabilization', | |
0ca4b209 | 49 | ]; |
1d8a8d12 | 50 | foreach ($optionValues as $name => $label) { |
0ca4b209 D |
51 | $activityTypes = CRM_Core_BAO_OptionValue::ensureOptionValueExists([ |
52 | 'option_group_id' => 'activity_type', | |
1d8a8d12 TO |
53 | 'name' => $name, |
54 | 'label' => $label, | |
0ca4b209 D |
55 | 'component_id' => 'CiviCase', |
56 | ]); | |
1d8a8d12 | 57 | // store for cleanup |
0ca4b209 | 58 | // @todo is this ever used? |
1d8a8d12 TO |
59 | $this->optionValues[] = $activityTypes['id']; |
60 | } | |
bb68492c | 61 | |
82de141d TO |
62 | // We used to be inconsistent about "HousingSupport" vs "housing_support". |
63 | // Now, the rule is simply: use the "name" from "civicrm_case_type.name". | |
64 | $this->caseType = 'housing_support'; | |
1d8a8d12 TO |
65 | $this->caseTypeId = 1; |
66 | $this->tablesToTruncate = array( | |
67 | 'civicrm_activity', | |
68 | 'civicrm_contact', | |
69 | 'civicrm_custom_group', | |
70 | 'civicrm_custom_field', | |
71 | 'civicrm_case', | |
72 | 'civicrm_case_contact', | |
73 | 'civicrm_case_activity', | |
74 | 'civicrm_case_type', | |
75 | 'civicrm_activity_contact', | |
10ffff26 | 76 | 'civicrm_managed', |
1d8a8d12 TO |
77 | 'civicrm_relationship', |
78 | 'civicrm_relationship_type', | |
225d474b | 79 | 'civicrm_uf_match', |
1d8a8d12 TO |
80 | ); |
81 | ||
82 | $this->quickCleanup($this->tablesToTruncate); | |
83 | ||
84 | $this->loadAllFixtures(); | |
85 | ||
86 | // enable the default custom templates for the case type xml files | |
87 | $this->customDirectories(array('template_path' => TRUE)); | |
88 | ||
89 | // case is not enabled by default | |
90 | $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); | |
91 | $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); | |
92 | ||
edbcbd96 TO |
93 | /** @var $hooks \CRM_Utils_Hook_UnitTests */ |
94 | $hooks = \CRM_Utils_Hook::singleton(); | |
95 | $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); | |
96 | \CRM_Case_XMLRepository::singleton(TRUE); | |
97 | \CRM_Case_XMLProcessor::flushStaticCaches(); | |
98 | ||
1d8a8d12 TO |
99 | // create a logged in USER since the code references it for source_contact_id |
100 | $this->createLoggedInUser(); | |
101 | $session = CRM_Core_Session::singleton(); | |
102 | $this->_loggedInUser = $session->get('userID'); | |
103 | /// note that activityType options are cached by the FULL set of options you pass in | |
104 | // ie. because Activity api includes campaign in it's call cache is not flushed unless | |
105 | // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array | |
106 | CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); | |
107 | } | |
108 | ||
109 | /** | |
110 | * Tears down the fixture, for example, closes a network connection. | |
111 | * This method is called after a test is executed. | |
1d8a8d12 | 112 | */ |
5d345864 | 113 | public function tearDown(): void { |
1d8a8d12 TO |
114 | $this->quickCleanup($this->tablesToTruncate, TRUE); |
115 | $this->customDirectories(array('template_path' => FALSE)); | |
bb68492c TO |
116 | CRM_Case_XMLRepository::singleton(TRUE); |
117 | } | |
118 | ||
119 | /** | |
120 | * Subclasses may override this if they want to be explicit about the case-type definition. | |
121 | * | |
122 | * @param $caseTypes | |
123 | * @see CRM_Utils_Hook::caseTypes | |
124 | */ | |
00be9182 | 125 | public function hook_caseTypes(&$caseTypes) { |
1d8a8d12 | 126 | } |
96025800 | 127 | |
ef10e0b5 | 128 | } |