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