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 TO |
17 | /** |
18 | * @var string symbolic-name | |
19 | */ | |
20 | protected $caseType; | |
21 | ||
1d8a8d12 | 22 | protected $caseTypeId; |
bb68492c | 23 | |
1d8a8d12 | 24 | protected $caseStatusGroup; |
bb68492c | 25 | |
1d8a8d12 | 26 | protected $optionValues; |
bb68492c | 27 | |
1d8a8d12 TO |
28 | protected $_loggedInUser; |
29 | ||
30 | public function setUp() { | |
31 | parent::setUp(); | |
bb68492c | 32 | |
1d8a8d12 TO |
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( | |
39b959db SL |
38 | 'name' => 'case_status', |
39 | 'format.only_id' => 1, | |
40 | )); | |
0ca4b209 | 41 | $optionValues = [ |
1d8a8d12 TO |
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', | |
0ca4b209 | 48 | ]; |
1d8a8d12 | 49 | foreach ($optionValues as $name => $label) { |
0ca4b209 D |
50 | $activityTypes = CRM_Core_BAO_OptionValue::ensureOptionValueExists([ |
51 | 'option_group_id' => 'activity_type', | |
1d8a8d12 TO |
52 | 'name' => $name, |
53 | 'label' => $label, | |
0ca4b209 D |
54 | 'component_id' => 'CiviCase', |
55 | ]); | |
1d8a8d12 | 56 | // store for cleanup |
0ca4b209 | 57 | // @todo is this ever used? |
1d8a8d12 TO |
58 | $this->optionValues[] = $activityTypes['id']; |
59 | } | |
bb68492c | 60 | |
82de141d TO |
61 | // We used to be inconsistent about "HousingSupport" vs "housing_support". |
62 | // Now, the rule is simply: use the "name" from "civicrm_case_type.name". | |
63 | $this->caseType = 'housing_support'; | |
1d8a8d12 TO |
64 | $this->caseTypeId = 1; |
65 | $this->tablesToTruncate = array( | |
66 | 'civicrm_activity', | |
67 | 'civicrm_contact', | |
68 | 'civicrm_custom_group', | |
69 | 'civicrm_custom_field', | |
70 | 'civicrm_case', | |
71 | 'civicrm_case_contact', | |
72 | 'civicrm_case_activity', | |
73 | 'civicrm_case_type', | |
74 | 'civicrm_activity_contact', | |
10ffff26 | 75 | 'civicrm_managed', |
1d8a8d12 TO |
76 | 'civicrm_relationship', |
77 | 'civicrm_relationship_type', | |
225d474b | 78 | 'civicrm_uf_match', |
1d8a8d12 TO |
79 | ); |
80 | ||
81 | $this->quickCleanup($this->tablesToTruncate); | |
82 | ||
83 | $this->loadAllFixtures(); | |
84 | ||
85 | // enable the default custom templates for the case type xml files | |
86 | $this->customDirectories(array('template_path' => TRUE)); | |
87 | ||
88 | // case is not enabled by default | |
89 | $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); | |
90 | $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); | |
91 | ||
edbcbd96 TO |
92 | /** @var $hooks \CRM_Utils_Hook_UnitTests */ |
93 | $hooks = \CRM_Utils_Hook::singleton(); | |
94 | $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); | |
95 | \CRM_Case_XMLRepository::singleton(TRUE); | |
96 | \CRM_Case_XMLProcessor::flushStaticCaches(); | |
97 | ||
1d8a8d12 TO |
98 | // create a logged in USER since the code references it for source_contact_id |
99 | $this->createLoggedInUser(); | |
100 | $session = CRM_Core_Session::singleton(); | |
101 | $this->_loggedInUser = $session->get('userID'); | |
102 | /// note that activityType options are cached by the FULL set of options you pass in | |
103 | // ie. because Activity api includes campaign in it's call cache is not flushed unless | |
104 | // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array | |
105 | CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Tears down the fixture, for example, closes a network connection. | |
110 | * This method is called after a test is executed. | |
1d8a8d12 | 111 | */ |
00be9182 | 112 | public function tearDown() { |
1d8a8d12 TO |
113 | $this->quickCleanup($this->tablesToTruncate, TRUE); |
114 | $this->customDirectories(array('template_path' => FALSE)); | |
bb68492c TO |
115 | CRM_Case_XMLRepository::singleton(TRUE); |
116 | } | |
117 | ||
118 | /** | |
119 | * Subclasses may override this if they want to be explicit about the case-type definition. | |
120 | * | |
121 | * @param $caseTypes | |
122 | * @see CRM_Utils_Hook::caseTypes | |
123 | */ | |
00be9182 | 124 | public function hook_caseTypes(&$caseTypes) { |
1d8a8d12 | 125 | } |
96025800 | 126 | |
ef10e0b5 | 127 | } |