add autogenerated comment blocks to tests dir
[civicrm-core.git] / tests / phpunit / api / v3 / CaseTypeTest.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 api_v3_CaseTypeTest
32 */
33 class api_v3_CaseTypeTest extends CiviUnitTestCase {
34 protected $_apiversion = 3;
35
36 function setUp() {
37 $this->_entity = 'CaseType';
38
39 parent::setUp();
40 $this->_apiversion = 3;
41 $this->tablesToTruncate = array(
42 'civicrm_case_type',
43 );
44 $this->quickCleanup($this->tablesToTruncate);
45 $this->createLoggedInUser();
46 $session = CRM_Core_Session::singleton();
47 $this->_loggedInUser = $session->get('userID');
48
49 }
50
51 /**
52 * Tears down the fixture, for example, closes a network connection.
53 * This method is called after a test is executed.
54 *
55 */
56 function tearDown() {
57 $this->quickCleanup($this->tablesToTruncate, TRUE);
58 }
59
60 /**
61 * check with empty array
62 */
63 function testCaseTypeCreateEmpty() {
64 $this->callAPIFailure('CaseType', 'create', array());
65 }
66
67 /**
68 * check if required fields are not passed
69 */
70 function testCaseTypeCreateWithoutRequired() {
71 $params = array(
72 'name' => 'this case should fail',
73 );
74 $this->callAPIFailure('CaseType', 'create', $params);
75
76 $params = array(
77 'name' => 'this case should fail',
78 'weight' => 4,
79 );
80 $this->callAPIFailure('CaseType', 'create', $params);
81 }
82
83 /**
84 * test create methods with valid data
85 * success expected
86 */
87 function testCaseTypeCreate() {
88 // Create Case Type
89 $params = array(
90 'title' => 'Application',
91 'name' => 'Application',
92 'is_active' => 1,
93 'weight' => 4,
94 );
95
96 $result = $this->callAPISuccess('CaseType', 'create', $params);
97 $id = $result['id'];
98
99 // Check result
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__);
103 }
104
105 /**
106 * Test update (create with id) function with valid parameters
107 */
108 function testCaseTypeUpdate() {
109 // Create Case Type
110 $params = array(
111 'title' => 'Application',
112 'name' => 'Application',
113 'is_active' => 1,
114 'weight' => 4,
115 );
116 $result = $this->callAPISuccess('CaseType', 'create', $params);
117 $id = $result['id'];
118 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
119 $caseType = $result['values'][$id];
120
121 // Update Case Type
122 $params = array('id' => $id);
123 $params['title'] = $caseType['title'] = 'Something Else';
124 $this->callAPISuccess('CaseType', 'create', $params);
125
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__);
129 }
130
131 /**
132 * Test delete function with valid parameters
133 */
134 function testCaseTypeDelete() {
135 // Create Case Type
136 $params = array(
137 'title' => 'Application',
138 'name' => 'Application',
139 'is_active' => 1,
140 'weight' => 4,
141 );
142 $result = $this->callAPISuccess('CaseType', 'create', $params);
143
144 $id = $result['id'];
145 $this->callAPISuccess('CaseType', 'delete', array('id' => $id));
146
147 // Check result - case type should no longer exist
148 $result = $this->callAPISuccess('CaseType', 'get', array('id' => $id));
149 $this->assertEquals(0, $result['count']);
150 }
151
152 /**
153 * test create methods with xml file
154 * success expected
155 */
156 function testCaseTypeCreateWithXML() {
157 $caseXMLFile = dirname(__FILE__) . '/dataset/sample_case.xml';
158
159 // Create Case Type
160 $params = array(
161 'title' => 'Application with XML',
162 'name' => 'Application_with_XML',
163 'is_active' => 1,
164 'weight' => 4,
165 'definition' => file_get_contents($caseXMLFile),
166 );
167
168 $result = $this->callAPISuccess('CaseType', 'create', $params);
169 $id = $result['id'];
170
171 // Check result
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__);
176 }
177 }
178