3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
29 * Class api_v3_CaseTypeTest
32 class api_v3_CaseTypeTest
extends CiviCaseTestCase
{
34 public function setUp() {
35 $this->quickCleanup(array('civicrm_case_type'));
38 $this->fixtures
['Application_with_Definition'] = array(
39 'title' => 'Application with Definition',
40 'name' => 'Application_with_Definition',
43 'definition' => array(
44 'activityTypes' => array(
45 array('name' => 'First act'),
47 'activitySets' => array(
52 'activityTypes' => array(
53 array('name' => 'Open Case', 'status' => 'Completed'),
58 array('name' => 'First role', 'creator' => 1, 'manager' => 1),
65 * 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', 'civicrm_uf_match'));
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.
102 public function testCaseTypeCreate() {
105 'title' => 'Application',
106 'name' => 'Application',
111 $result = $this->callAPISuccess('CaseType', 'create', $params);
115 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
116 $this->assertEquals($result['values'][$id]['id'], $id);
117 $this->assertEquals($result['values'][$id]['title'], $params['title']);
121 * Create a case with an invalid name.
123 public function testCaseTypeCreate_invalidName() {
126 'title' => 'Application',
127 'name' => 'Appl ication', // spaces are not allowed
132 $this->callAPIFailure('CaseType', 'create', $params);
137 * Test update (create with id) function with valid parameters.
139 public function testCaseTypeUpdate() {
142 'title' => 'Application',
143 'name' => 'Application',
147 $result = $this->callAPISuccess('CaseType', 'create', $params);
149 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
150 $caseType = $result['values'][$id];
153 $params = array('id' => $id);
154 $params['title'] = $caseType['title'] = 'Something Else';
155 $this->callAPISuccess('CaseType', 'create', $params);
157 // Verify that updated case Type is exactly equal to the original with new title.
158 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
159 $this->assertEquals($result['values'][$id], $caseType);
163 * Test delete function with valid parameters.
165 public function testCaseTypeDelete_New() {
168 'title' => 'Application',
169 'name' => 'Application',
173 $result = $this->callAPISuccess('CaseType', 'create', $params);
176 $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
178 // Check result - case type should no longer exist
179 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
180 $this->assertEquals(0, $result['count']);
184 * Test create methods with xml file.
188 public function testCaseTypeCreateWithDefinition() {
190 $params = $this->fixtures
['Application_with_Definition'];
191 $result = $this->callAPISuccess('CaseType', 'create', $params);
195 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
196 $this->assertEquals($result['values'][$id]['id'], $id);
197 $this->assertEquals($result['values'][$id]['title'], $params['title']);
198 $this->assertEquals($result['values'][$id]['definition'], $params['definition']);
200 $caseXml = CRM_Case_XMLRepository
::singleton()->retrieve('Application_with_Definition');
201 $this->assertTrue($caseXml instanceof SimpleXMLElement
);
205 * Create a CaseType+case then delete the CaseType.
207 public function testCaseTypeDelete_InUse() {
209 $params = $this->fixtures
['Application_with_Definition'];
210 $createCaseType = $this->callAPISuccess('CaseType', 'create', $params);
212 $createCase = $this->callAPISuccess('Case', 'create', array(
213 'case_type_id' => $createCaseType['id'],
214 'contact_id' => $this->_loggedInUser
,
215 'subject' => 'Example',
218 // Deletion fails while case-type is in-use
219 $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id']));
220 $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']);
221 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
222 $this->assertEquals(1, $getCaseType['count']);
224 // Deletion succeeds when it's not in-use.
225 $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id']));
227 // Check result - case type should no longer exist.
228 $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id']));
229 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
230 $this->assertEquals(0, $getCaseType['count']);