Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
31 | ||
32 | ||
33 | /** | |
34 | * Test class for GroupOrganization API - civicrm_group_organization_* | |
35 | * | |
36 | * @package CiviCRM | |
37 | */ | |
38 | class api_v3_GroupOrganizationTest extends CiviUnitTestCase { | |
39 | protected $_apiversion; | |
40 | public $_eNoticeCompliant = True; | |
41 | ||
42 | function get_info() { | |
43 | return array( | |
44 | 'name' => 'Group Organization', | |
45 | 'description' => 'Test all Group Organization API methods.', | |
46 | 'group' => 'CiviCRM API Tests', | |
47 | ); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Sets up the fixture, for example, opens a network connection. | |
52 | * This method is called before a test is executed. | |
53 | * | |
54 | * @access protected | |
55 | */ | |
56 | protected function setUp() { | |
57 | $this->_apiversion = 3; | |
58 | parent::setUp(); | |
59 | $this->_groupID = $this->groupCreate(NULL); | |
60 | ||
61 | $this->_orgID = $this->organizationCreate(NULL); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Tears down the fixture, for example, closes a network connection. | |
66 | * This method is called after a test is executed. | |
67 | * | |
68 | * @access protected | |
69 | */ | |
70 | protected function tearDown() { | |
71 | // Truncate the tables | |
72 | $this->quickCleanup( | |
73 | array( | |
74 | 'civicrm_group', | |
75 | 'civicrm_group_organization', | |
76 | 'civicrm_contact', | |
77 | 'civicrm_uf_group', | |
78 | 'civicrm_uf_join', | |
79 | 'civicrm_uf_match', | |
80 | ) | |
81 | ); | |
82 | } | |
83 | ||
84 | ///////////////// civicrm_group_organization_get methods | |
85 | ||
86 | /** | |
87 | * Test civicrm_group_organization_get with valid params. | |
88 | */ | |
89 | public function testGroupOrganizationGet() { | |
90 | ||
91 | $params = array( | |
92 | 'organization_id' => $this->_orgID, | |
93 | 'group_id' => $this->_groupID, | |
94 | 'version' => $this->_apiversion, | |
95 | ); | |
96 | $result = civicrm_api('group_organization', 'create', $params); | |
97 | $paramsGet = array( | |
98 | 'organization_id' => $result['id'], | |
99 | 'version' => $this->_apiversion, | |
100 | ); | |
101 | $result = civicrm_api('group_organization', 'get', $paramsGet); | |
102 | $this->documentMe($paramsGet, $result, __FUNCTION__, __FILE__); | |
103 | $this->assertEquals($result['is_error'], 0); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Test civicrm_group_organization_get with group_id. | |
108 | */ | |
109 | public function testGroupOrganizationGetWithGroupId() { | |
110 | ||
111 | $params = array( | |
112 | 'organization_id' => $this->_orgID, | |
113 | 'group_id' => $this->_groupID, | |
114 | 'version' => $this->_apiversion, | |
115 | 'sequential' => 1, | |
116 | ); | |
117 | $result = civicrm_api('group_organization', 'create', $params); | |
118 | ||
119 | $paramsGet = array('organization_id' => $result['values'][0]['organization_id']); | |
120 | ||
121 | $result = civicrm_api('group_organization', 'get', $params); | |
122 | $this->assertEquals($result['is_error'], 0); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Test civicrm_group_organization_get with empty params. | |
127 | */ | |
128 | public function testGroupOrganizationGetWithEmptyParams() { | |
129 | $params = array( | |
130 | 'version' => $this->_apiversion, | |
131 | ); | |
132 | $result = civicrm_api('group_organization', 'get', $params); | |
133 | ||
134 | $this->assertEquals($result['is_error'], 0); | |
135 | } | |
136 | ||
137 | /** | |
138 | * Test civicrm_group_organization_get with wrong params. | |
139 | */ | |
140 | public function testGroupOrganizationGetWithWrongParams() { | |
141 | $params = 'groupOrg'; | |
142 | $result = civicrm_api('group_organization', 'get', $params); | |
143 | ||
144 | $this->assertEquals($result['is_error'], 1); | |
145 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); | |
146 | } | |
147 | ||
148 | /** | |
149 | * Test civicrm_group_organization_get invalid keys. | |
150 | */ | |
151 | public function testGroupOrganizationGetWithInvalidKeys() { | |
152 | $params = array( | |
153 | 'invalid_key' => 1, | |
154 | 'version' => $this->_apiversion, | |
155 | ); | |
156 | $result = civicrm_api('group_organization', 'get', $params); | |
157 | ||
158 | $this->assertEquals($result['is_error'], 0); | |
159 | } | |
160 | ||
161 | ///////////////// civicrm_group_organization_create methods | |
162 | ||
163 | /** | |
164 | * check with valid params | |
165 | */ | |
166 | public function testGroupOrganizationCreate() { | |
167 | $params = array( | |
168 | 'organization_id' => $this->_orgID, | |
169 | 'group_id' => $this->_groupID, | |
170 | 'version' => $this->_apiversion, | |
171 | ); | |
172 | $result = civicrm_api('group_organization', 'create', $params); | |
173 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
174 | $this->assertAPISuccess($result, "in line " . __LINE__); | |
175 | } | |
176 | ||
177 | /** | |
178 | * check with empty params array | |
179 | */ | |
180 | public function testGroupOrganizationCreateWithEmptyParams() { | |
181 | $params = array( | |
182 | 'version' => $this->_apiversion, | |
183 | ); | |
184 | $result = civicrm_api('group_organization', 'create', $params); | |
185 | ||
186 | $this->assertEquals($result['is_error'], 1); | |
187 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); | |
188 | } | |
189 | ||
190 | /** | |
191 | * check with invalid params | |
192 | */ | |
193 | public function testGroupOrganizationCreateParamsNotArray() { | |
194 | $params = 'group_org'; | |
195 | $result = civicrm_api('group_organization', 'create', $params); | |
196 | ||
197 | $this->assertEquals($result['is_error'], 1); | |
198 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); | |
199 | } | |
200 | ||
201 | /** | |
202 | * check with invalid params keys | |
203 | */ | |
204 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
205 | $params = array( | |
206 | 'invalid_key' => 1, | |
207 | 'version' => $this->_apiversion, | |
208 | ); | |
209 | $result = civicrm_api('group_organization', 'create', $params); | |
210 | ||
211 | $this->assertEquals($result['is_error'], 1); | |
212 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); | |
213 | } | |
214 | ||
215 | ///////////////// civicrm_group_organization_remove methods | |
216 | ||
217 | /** | |
218 | * Test civicrm_group_organization_remove with params not an array. | |
219 | */ | |
220 | public function testGroupOrganizationDeleteParamsNotArray() { | |
221 | $params = 'delete'; | |
222 | $result = civicrm_api('group_organization', 'delete', $params); | |
223 | ||
224 | $this->assertEquals($result['is_error'], 1); | |
225 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); | |
226 | } | |
227 | ||
228 | /** | |
229 | * Test civicrm_group_organization_remove with empty params. | |
230 | */ | |
231 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
232 | $params = array( | |
233 | 'version' => $this->_apiversion, | |
234 | ); | |
235 | $result = civicrm_api('group_organization', 'delete', $params); | |
236 | ||
237 | $this->assertEquals($result['is_error'], 1); | |
238 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); | |
239 | } | |
240 | ||
241 | /** | |
242 | * Test civicrm_group_organization_remove with valid params. | |
243 | */ | |
244 | public function testGroupOrganizationDelete() { | |
245 | $paramsC = array( | |
246 | 'organization_id' => $this->_orgID, | |
247 | 'group_id' => $this->_groupID, | |
248 | 'version' => $this->_apiversion, | |
249 | ); | |
250 | $result = civicrm_api('group_organization', 'create', $paramsC); | |
251 | ||
252 | $params = array( | |
253 | 'id' => $result['id'], | |
254 | 'version' => $this->_apiversion, | |
255 | ); | |
256 | $result = civicrm_api('group_organization', 'delete', $params); | |
257 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
258 | $this->assertAPISuccess($result, "in line " . __LINE__); | |
259 | } | |
260 | ||
261 | /** | |
262 | * Test civicrm_group_organization_remove with invalid params key. | |
263 | */ | |
264 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
265 | $paramsDelete = array( | |
266 | 'invalid_key' => 1, | |
267 | 'version' => $this->_apiversion, | |
268 | ); | |
269 | $result = civicrm_api('group_organization', 'delete', $paramsDelete); | |
270 | ||
271 | $this->assertEquals($result['is_error'], 1); | |
272 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); | |
273 | } | |
274 | } | |
275 |