Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-23-18-25-12
[civicrm-core.git] / tests / phpunit / CiviTest / CiviCaseTestCase.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Class CiviReportTestCase
32 */
33 class CiviCaseTestCase extends CiviUnitTestCase {
34
35 /**
36 * @var string symbolic-name
37 */
38 protected $caseType;
39
40 protected $caseTypeId;
41
42 protected $caseStatusGroup;
43
44 protected $optionValues;
45
46 protected $_loggedInUser;
47
48 public function setUp() {
49 parent::setUp();
50
51 /** @var $hooks \CRM_Utils_Hook_UnitTests */
52 $hooks = \CRM_Utils_Hook::singleton();
53 $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
54 \CRM_Case_XMLRepository::singleton(TRUE);
55
56 // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
57 //. Using XML was causing breakage as id numbers were changing over time
58 // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
59 // state where tests could run afterwards without re-loading.
60 $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array(
61 'name' => 'case_status',
62 'format.only_id' => 1
63 )
64 );
65 $optionValues = array(
66 'Medical evaluation' => 'Medical evaluation',
67 'Mental health evaluation' => "Mental health evaluation",
68 'Secure temporary housing' => 'Secure temporary housing',
69 'Long-term housing plan' => 'Long-term housing plan',
70 'ADC referral' => 'ADC referral',
71 'Income and benefits stabilization' => 'Income and benefits stabilization',
72 );
73 foreach ($optionValues as $name => $label) {
74 $activityTypes = $this->callAPISuccess('option_value', 'Create', array(
75 'option_group_id' => 2,
76 'name' => $name,
77 'label' => $label,
78 'component_id' => 7,
79 ));
80 // store for cleanup
81 $this->optionValues[] = $activityTypes['id'];
82 }
83
84 // TODO Our data seems inconsistent on whether name is "HousingSupport" or "housing_support"
85 $this->caseType = 'HousingSupport';
86 $this->caseTypeId = 1;
87 $this->tablesToTruncate = array(
88 'civicrm_activity',
89 'civicrm_contact',
90 'civicrm_custom_group',
91 'civicrm_custom_field',
92 'civicrm_case',
93 'civicrm_case_contact',
94 'civicrm_case_activity',
95 'civicrm_case_type',
96 'civicrm_activity_contact',
97 'civicrm_relationship',
98 'civicrm_relationship_type',
99 );
100
101 $this->quickCleanup($this->tablesToTruncate);
102
103 $this->loadAllFixtures();
104
105 // enable the default custom templates for the case type xml files
106 $this->customDirectories(array('template_path' => TRUE));
107
108 // case is not enabled by default
109 $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
110 $this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
111
112 // create a logged in USER since the code references it for source_contact_id
113 $this->createLoggedInUser();
114 $session = CRM_Core_Session::singleton();
115 $this->_loggedInUser = $session->get('userID');
116 /// note that activityType options are cached by the FULL set of options you pass in
117 // ie. because Activity api includes campaign in it's call cache is not flushed unless
118 // included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
119 CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
120 }
121
122 /**
123 * Tears down the fixture, for example, closes a network connection.
124 * This method is called after a test is executed.
125 *
126 * @access protected
127 */
128 function tearDown() {
129 $this->quickCleanup($this->tablesToTruncate, TRUE);
130 $this->customDirectories(array('template_path' => FALSE));
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 */
140 function hook_caseTypes(&$caseTypes) {
141 }
142 }