3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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/CiviUnitTestCase.php';
31 * Class api_v3_CaseTypeTest
33 class api_v3_CaseTypeTest
extends CiviUnitTestCase
{
34 protected $_apiversion = 3;
37 $this->_entity
= 'CaseType';
40 $this->_apiversion
= 3;
41 $this->tablesToTruncate
= array(
44 $this->quickCleanup($this->tablesToTruncate
);
45 $this->createLoggedInUser();
46 $session = CRM_Core_Session
::singleton();
47 $this->_loggedInUser
= $session->get('userID');
52 * Tears down the fixture, for example, closes a network connection.
53 * This method is called after a test is executed.
57 $this->quickCleanup($this->tablesToTruncate
, TRUE);
61 * check with empty array
63 function testCaseTypeCreateEmpty() {
64 $this->callAPIFailure('CaseType', 'create', array());
68 * check if required fields are not passed
70 function testCaseTypeCreateWithoutRequired() {
72 'name' => 'this case should fail',
74 $this->callAPIFailure('CaseType', 'create', $params);
77 'name' => 'this case should fail',
80 $this->callAPIFailure('CaseType', 'create', $params);
84 * test create methods with valid data
87 function testCaseTypeCreate() {
90 'title' => 'Application',
91 'name' => 'Application',
96 $result = $this->callAPISuccess('CaseType', 'create', $params);
100 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
101 $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__
);
102 $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__
);
106 * Test update (create with id) function with valid parameters
108 function testCaseTypeUpdate() {
111 'title' => 'Application',
112 'name' => 'Application',
116 $result = $this->callAPISuccess('CaseType', 'create', $params);
118 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
119 $caseType = $result['values'][$id];
122 $params = array('id' => $id);
123 $params['title'] = $caseType['title'] = 'Something Else';
124 $this->callAPISuccess('CaseType', 'create', $params);
126 // Verify that updated case Type is exactly equal to the original with new title
127 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
128 $this->assertEquals($result['values'][$id], $caseType, 'in line ' . __LINE__
);
132 * Test delete function with valid parameters
134 function testCaseTypeDelete() {
137 'title' => 'Application',
138 'name' => 'Application',
142 $result = $this->callAPISuccess('CaseType', 'create', $params);
145 $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
147 // Check result - case type should no longer exist
148 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
149 $this->assertEquals(0, $result['count']);
153 * test create methods with xml file
156 function testCaseTypeCreateWithXML() {
157 $caseXMLFile = dirname(__FILE__
) . '/dataset/sample_case.xml';
161 'title' => 'Application with XML',
162 'name' => 'Application_with_XML',
165 'definition' => file_get_contents($caseXMLFile),
168 $result = $this->callAPISuccess('CaseType', 'create', $params);
172 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
173 $this->assertEquals($result['values'][$id]['id'], $id, 'in line ' . __LINE__
);
174 $this->assertEquals($result['values'][$id]['title'], $params['title'], 'in line ' . __LINE__
);
175 $this->assertEquals($result['values'][$id]['xml_definition'], $params['xml_definition'], 'in line ' . __LINE__
);