3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
34 class api_v3_CaseTypeTest
extends CiviCaseTestCase
{
36 public function setUp() {
37 $this->quickCleanup(array('civicrm_case_type'));
40 $this->fixtures
['Application_with_Definition'] = array(
41 'title' => 'Application with Definition',
42 'name' => 'Application_with_Definition',
45 'definition' => array(
46 'activityTypes' => array(
47 array('name' => 'First act'),
49 'activitySets' => array(
54 'activityTypes' => array(
55 array('name' => 'Open Case', 'status' => 'Completed'),
60 array('name' => 'First role', 'creator' => 1, 'manager' => 1),
67 * Tears down the fixture, for example, closes a network connection.
69 * This method is called after a test is executed.
71 public function tearDown() {
73 $this->quickCleanup(array('civicrm_case_type', 'civicrm_uf_match'));
77 * Check with empty array.
79 public function testCaseTypeCreateEmpty() {
80 $this->callAPIFailure('CaseType', 'create', array());
84 * Check if required fields are not passed.
86 public function testCaseTypeCreateWithoutRequired() {
88 'name' => 'this case should fail',
90 $this->callAPIFailure('CaseType', 'create', $params);
93 'name' => 'this case should fail',
96 $this->callAPIFailure('CaseType', 'create', $params);
100 * Test create methods with valid data.
104 public function testCaseTypeCreate() {
107 'title' => 'Application',
108 'name' => 'Application',
113 $result = $this->callAPISuccess('CaseType', 'create', $params);
117 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
118 $this->assertEquals($result['values'][$id]['id'], $id);
119 $this->assertEquals($result['values'][$id]['title'], $params['title']);
123 * Create a case with an invalid name.
125 public function testCaseTypeCreate_invalidName() {
128 'title' => 'Application',
129 'name' => 'Appl ication', // spaces are not allowed
134 $this->callAPIFailure('CaseType', 'create', $params);
139 * Test update (create with id) function with valid parameters.
141 public function testCaseTypeUpdate() {
144 'title' => 'Application',
145 'name' => 'Application',
149 $result = $this->callAPISuccess('CaseType', 'create', $params);
151 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
152 $caseType = $result['values'][$id];
155 $params = array('id' => $id);
156 $params['title'] = $caseType['title'] = 'Something Else';
157 $this->callAPISuccess('CaseType', 'create', $params);
159 // Verify that updated case Type is exactly equal to the original with new title.
160 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
161 $this->assertEquals($result['values'][$id], $caseType);
165 * Test delete function with valid parameters.
167 public function testCaseTypeDelete_New() {
170 'title' => 'Application',
171 'name' => 'Application',
175 $result = $this->callAPISuccess('CaseType', 'create', $params);
178 $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
180 // Check result - case type should no longer exist
181 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
182 $this->assertEquals(0, $result['count']);
186 * Test create methods with xml file.
190 public function testCaseTypeCreateWithDefinition() {
192 $params = $this->fixtures
['Application_with_Definition'];
193 $result = $this->callAPISuccess('CaseType', 'create', $params);
197 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
198 $this->assertEquals($result['values'][$id]['id'], $id);
199 $this->assertEquals($result['values'][$id]['title'], $params['title']);
200 $this->assertEquals($result['values'][$id]['definition'], $params['definition']);
202 $caseXml = CRM_Case_XMLRepository
::singleton()->retrieve('Application_with_Definition');
203 $this->assertTrue($caseXml instanceof SimpleXMLElement
);
207 * Create a CaseType+case then delete the CaseType.
209 public function testCaseTypeDelete_InUse() {
211 $params = $this->fixtures
['Application_with_Definition'];
212 $createCaseType = $this->callAPISuccess('CaseType', 'create', $params);
214 $createCase = $this->callAPISuccess('Case', 'create', array(
215 'case_type_id' => $createCaseType['id'],
216 'contact_id' => $this->_loggedInUser
,
217 'subject' => 'Example',
220 // Deletion fails while case-type is in-use
221 $deleteCaseType = $this->callAPIFailure('CaseType', 'delete', array('id' => $createCaseType['id']));
222 $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']);
223 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
224 $this->assertEquals(1, $getCaseType['count']);
226 // Deletion succeeds when it's not in-use.
227 $this->callAPISuccess('Case', 'delete', array('id' => $createCase['id']));
229 // Check result - case type should no longer exist.
230 $this->callAPISuccess('CaseType', 'delete', array('id' => $createCaseType['id']));
231 $getCaseType = $this->callAPISuccess('CaseType', 'get', array('id' => $createCaseType['id']));
232 $this->assertEquals(0, $getCaseType['count']);