Commit | Line | Data |
---|---|---|
1d8a8d12 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
1d8a8d12 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
1d8a8d12 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
1d8a8d12 | 27 | |
1d8a8d12 TO |
28 | /** |
29 | * Class CiviReportTestCase | |
30 | */ | |
31 | class CiviCaseTestCase extends CiviUnitTestCase { | |
32 | ||
bb68492c TO |
33 | /** |
34 | * @var string symbolic-name | |
35 | */ | |
36 | protected $caseType; | |
37 | ||
1d8a8d12 | 38 | protected $caseTypeId; |
bb68492c | 39 | |
1d8a8d12 | 40 | protected $caseStatusGroup; |
bb68492c | 41 | |
1d8a8d12 | 42 | protected $optionValues; |
bb68492c | 43 | |
1d8a8d12 TO |
44 | protected $_loggedInUser; |
45 | ||
46 | public function setUp() { | |
47 | parent::setUp(); | |
bb68492c | 48 | |
1d8a8d12 TO |
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', | |
21dfd5f5 | 55 | 'format.only_id' => 1, |
1d8a8d12 TO |
56 | ) |
57 | ); | |
58 | $optionValues = array( | |
59 | 'Medical evaluation' => 'Medical evaluation', | |
60 | 'Mental health evaluation' => "Mental health evaluation", | |
61 | 'Secure temporary housing' => 'Secure temporary housing', | |
62 | 'Long-term housing plan' => 'Long-term housing plan', | |
63 | 'ADC referral' => 'ADC referral', | |
64 | 'Income and benefits stabilization' => 'Income and benefits stabilization', | |
65 | ); | |
66 | foreach ($optionValues as $name => $label) { | |
67 | $activityTypes = $this->callAPISuccess('option_value', 'Create', array( | |
68 | 'option_group_id' => 2, | |
69 | 'name' => $name, | |
70 | 'label' => $label, | |
71 | 'component_id' => 7, | |
72 | )); | |
73 | // store for cleanup | |
74 | $this->optionValues[] = $activityTypes['id']; | |
75 | } | |
bb68492c | 76 | |
82de141d TO |
77 | // We used to be inconsistent about "HousingSupport" vs "housing_support". |
78 | // Now, the rule is simply: use the "name" from "civicrm_case_type.name". | |
79 | $this->caseType = 'housing_support'; | |
1d8a8d12 TO |
80 | $this->caseTypeId = 1; |
81 | $this->tablesToTruncate = array( | |
82 | 'civicrm_activity', | |
83 | 'civicrm_contact', | |
84 | 'civicrm_custom_group', | |
85 | 'civicrm_custom_field', | |
86 | 'civicrm_case', | |
87 | 'civicrm_case_contact', | |
88 | 'civicrm_case_activity', | |
89 | 'civicrm_case_type', | |
90 | 'civicrm_activity_contact', | |
10ffff26 | 91 | 'civicrm_managed', |
1d8a8d12 TO |
92 | 'civicrm_relationship', |
93 | 'civicrm_relationship_type', | |
225d474b | 94 | 'civicrm_uf_match', |
1d8a8d12 TO |
95 | ); |
96 | ||
97 | $this->quickCleanup($this->tablesToTruncate); | |
98 | ||
99 | $this->loadAllFixtures(); | |
100 | ||
101 | // enable the default custom templates for the case type xml files | |
102 | $this->customDirectories(array('template_path' => TRUE)); | |
103 | ||
104 | // case is not enabled by default | |
105 | $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); | |
106 | $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__); | |
107 | ||
edbcbd96 TO |
108 | /** @var $hooks \CRM_Utils_Hook_UnitTests */ |
109 | $hooks = \CRM_Utils_Hook::singleton(); | |
110 | $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); | |
111 | \CRM_Case_XMLRepository::singleton(TRUE); | |
112 | \CRM_Case_XMLProcessor::flushStaticCaches(); | |
113 | ||
1d8a8d12 TO |
114 | // create a logged in USER since the code references it for source_contact_id |
115 | $this->createLoggedInUser(); | |
116 | $session = CRM_Core_Session::singleton(); | |
117 | $this->_loggedInUser = $session->get('userID'); | |
118 | /// note that activityType options are cached by the FULL set of options you pass in | |
119 | // ie. because Activity api includes campaign in it's call cache is not flushed unless | |
120 | // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array | |
121 | CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE); | |
122 | } | |
123 | ||
124 | /** | |
125 | * Tears down the fixture, for example, closes a network connection. | |
126 | * This method is called after a test is executed. | |
1d8a8d12 | 127 | */ |
00be9182 | 128 | public function tearDown() { |
1d8a8d12 TO |
129 | $this->quickCleanup($this->tablesToTruncate, TRUE); |
130 | $this->customDirectories(array('template_path' => FALSE)); | |
bb68492c TO |
131 | CRM_Case_XMLRepository::singleton(TRUE); |
132 | } | |
133 | ||
134 | /** | |
135 | * Subclasses may override this if they want to be explicit about the case-type definition. | |
136 | * | |
137 | * @param $caseTypes | |
138 | * @see CRM_Utils_Hook::caseTypes | |
139 | */ | |
00be9182 | 140 | public function hook_caseTypes(&$caseTypes) { |
1d8a8d12 | 141 | } |
96025800 | 142 | |
ef10e0b5 | 143 | } |