3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviCaseTestCase.php';
31 * Class api_v3_CaseTypeTest
33 class api_v3_CaseTypeTest
extends CiviCaseTestCase
{
35 public function setUp() {
36 $this->quickCleanup(array('civicrm_case_type'));
39 $this->fixtures
['Application_with_Definition'] = array(
40 'title' => 'Application with Definition',
41 'name' => 'Application_with_Definition',
44 'definition' => array(
45 'activityTypes' => array(
46 array('name' => 'First act'),
48 'activitySets' => array(
53 'activityTypes' => array(
54 array('name' => 'Open Case', 'status' => 'Completed'),
59 array('name' => 'First role', 'creator' => 1, 'manager' => 1),
66 * Tears down the fixture, for example, closes a network connection.
67 * This method is called after a test is executed.
69 public function tearDown() {
71 $this->quickCleanup(array('civicrm_case_type'));
75 * Check with empty array
77 public function testCaseTypeCreateEmpty() {
78 $this->callAPIFailure('CaseType', 'create', array());
82 * Check if required fields are not passed
84 public function testCaseTypeCreateWithoutRequired() {
86 'name' => 'this case should fail',
88 $this->callAPIFailure('CaseType', 'create', $params);
91 'name' => 'this case should fail',
94 $this->callAPIFailure('CaseType', 'create', $params);
98 * Test create methods with valid data
101 public function testCaseTypeCreate() {
104 'title' => 'Application',
105 'name' => 'Application',
110 $result = $this->callAPISuccess('CaseType', 'create', $params);
114 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
115 $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__
);
116 $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__
);
120 * Create a case with an invalid name
122 public function testCaseTypeCreate_invalidName() {
125 'title' => 'Application',
126 'name' => 'Appl ication', // spaces are not allowed
131 $this->callAPIFailure('CaseType', 'create', $params);
136 * Test update (create with id) function with valid parameters
138 public function testCaseTypeUpdate() {
141 'title' => 'Application',
142 'name' => 'Application',
146 $result = $this->callAPISuccess('CaseType', 'create', $params);
148 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
149 $caseType = $result['values'][$id];
152 $params = array('id' => $id);
153 $params['title'] = $caseType['title'] = 'Something Else';
154 $this->callAPISuccess('CaseType', 'create', $params);
156 // Verify that updated case Type is exactly equal to the original with new title
157 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
158 $this->assertEquals($result['values'][$id], $caseType, 'in line ' . __LINE__
);
162 * Test delete function with valid parameters
164 public function testCaseTypeDelete_New() {
167 'title' => 'Application',
168 'name' => 'Application',
172 $result = $this->callAPISuccess('CaseType', 'create', $params);
175 $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
177 // Check result - case type should no longer exist
178 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
179 $this->assertEquals(0, $result['count']);
183 * Test create methods with xml file
186 public function testCaseTypeCreateWithDefinition() {
188 $params = $this->fixtures
['Application_with_Definition'];
189 $result = $this->callAPISuccess('CaseType', 'create', $params);
193 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
194 $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__
);
195 $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__
);
196 $this->assertEquals($result['values'][$id]['definition'], $params['definition'], 'in line ' . __LINE__
);
198 $caseXml = CRM_Case_XMLRepository
::singleton()->retrieve('Application_with_Definition');
199 $this->assertTrue($caseXml instanceof SimpleXMLElement
);
203 * Create a CaseType+case then delete the CaseType.
205 public function testCaseTypeDelete_InUse() {
207 $params = $this->fixtures
['Application_with_Definition'];
208 $createCaseType = $this->callAPISuccess('CaseType', 'create', $params);
210 $createCase = $this->callAPISuccess('Case', 'create', array(
211 'case_type_id' => $createCaseType['id'],
212 'contact_id' => $this->_loggedInUser
,
213 'subject' => 'Example',
216 // Deletion fails while case-type is in-use
217 $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id']));
218 $this->assertEquals("You can not delete this case type -- it is assigned to 1 existing case record(s). If you do not want this case type to be used going forward, consider disabling it instead.", $deleteCaseType['error_message']);
219 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
220 $this->assertEquals(1, $getCaseType['count']);
222 // Deletion succeeds when it's not in-use
223 $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id']));
225 // Check result - case type should no longer exist
226 $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id']));
227 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
228 $this->assertEquals(0, $getCaseType['count']);