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