Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | /** | |
32 | * Test class for GroupOrganization API - civicrm_group_organization_* | |
33 | * | |
34 | * @package CiviCRM | |
35 | */ | |
36 | class api_v3_GroupOrganizationTest extends CiviUnitTestCase { | |
37 | protected $_apiversion; | |
6a488035 | 38 | |
4cbe18b8 EM |
39 | /** |
40 | * @return array | |
41 | */ | |
6a488035 TO |
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(); | |
fadb804f | 59 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
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, | |
2d34d4bb | 93 | 'group_id' => $this->_groupID, ); |
94 | $result = $this->callAPISuccess('group_organization', 'create', $params); | |
6a488035 TO |
95 | $paramsGet = array( |
96 | 'organization_id' => $result['id'], | |
6a488035 | 97 | ); |
2d34d4bb | 98 | $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); |
6a488035 TO |
99 | } |
100 | ||
101 | /** | |
102 | * Test civicrm_group_organization_get with group_id. | |
103 | */ | |
104 | public function testGroupOrganizationGetWithGroupId() { | |
25396471 | 105 | $createParams = array( |
6a488035 | 106 | 'organization_id' => $this->_orgID, |
25396471 | 107 | 'group_id' => $this->_groupID, |
6a488035 | 108 | ); |
25396471 | 109 | $createResult = $this->callAPISuccess('group_organization', 'create', $createParams); |
6a488035 | 110 | |
25396471 TO |
111 | $getParams = array( |
112 | 'group_id' => $this->_groupID, | |
113 | 'sequential' => 1, | |
114 | ); | |
115 | $getResult = $this->callAPISuccess('group_organization', 'get', $getParams); | |
116 | $this->assertEquals($createResult['values'], $getResult['values'][0]); | |
6a488035 TO |
117 | } |
118 | ||
119 | /** | |
120 | * Test civicrm_group_organization_get with empty params. | |
121 | */ | |
122 | public function testGroupOrganizationGetWithEmptyParams() { | |
2d34d4bb | 123 | $params = array( ); |
124 | $result = $this->callAPISuccess('group_organization', 'get', $params); | |
6a488035 | 125 | |
791c263c | 126 | $this->assertAPISuccess($result); |
6a488035 TO |
127 | } |
128 | ||
129 | /** | |
130 | * Test civicrm_group_organization_get with wrong params. | |
131 | */ | |
132 | public function testGroupOrganizationGetWithWrongParams() { | |
133 | $params = 'groupOrg'; | |
d0e1eff2 | 134 | $result = $this->callAPIFailure('group_organization', 'get', $params); |
6a488035 TO |
135 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
136 | } | |
137 | ||
138 | /** | |
139 | * Test civicrm_group_organization_get invalid keys. | |
140 | */ | |
141 | public function testGroupOrganizationGetWithInvalidKeys() { | |
142 | $params = array( | |
2d34d4bb | 143 | 'invalid_key' => 1, ); |
144 | $result = $this->callAPISuccess('group_organization', 'get', $params); | |
6a488035 | 145 | |
791c263c | 146 | $this->assertAPISuccess($result); |
6a488035 TO |
147 | } |
148 | ||
149 | ///////////////// civicrm_group_organization_create methods | |
150 | ||
151 | /** | |
152 | * check with valid params | |
153 | */ | |
154 | public function testGroupOrganizationCreate() { | |
155 | $params = array( | |
156 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 157 | 'group_id' => $this->_groupID, ); |
158 | $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
159 | } |
160 | ||
c69fdfbb E |
161 | /** |
162 | * CRM-13841 - Load Group Org before save | |
163 | */ | |
164 | public function testGroupOrganizationCreateTwice() { | |
165 | $params = array( | |
166 | 'organization_id' => $this->_orgID, | |
167 | 'group_id' => $this->_groupID, ); | |
168 | $result = $this->callAPISuccess('group_organization', 'create', $params); | |
169 | $result2 = $this->callAPISuccess('group_organization', 'create', $params); | |
170 | $this->assertEquals($result['values'], $result2['values']); | |
171 | } | |
6a488035 TO |
172 | /** |
173 | * check with empty params array | |
174 | */ | |
175 | public function testGroupOrganizationCreateWithEmptyParams() { | |
2d34d4bb | 176 | $params = array( ); |
d0e1eff2 | 177 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
178 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
179 | } | |
180 | ||
181 | /** | |
182 | * check with invalid params | |
183 | */ | |
184 | public function testGroupOrganizationCreateParamsNotArray() { | |
185 | $params = 'group_org'; | |
d0e1eff2 | 186 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
187 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
188 | } | |
189 | ||
190 | /** | |
191 | * check with invalid params keys | |
192 | */ | |
193 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
194 | $params = array( | |
2d34d4bb | 195 | 'invalid_key' => 1, ); |
d0e1eff2 | 196 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
197 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
198 | } | |
199 | ||
200 | ///////////////// civicrm_group_organization_remove methods | |
201 | ||
202 | /** | |
203 | * Test civicrm_group_organization_remove with params not an array. | |
204 | */ | |
205 | public function testGroupOrganizationDeleteParamsNotArray() { | |
206 | $params = 'delete'; | |
d0e1eff2 | 207 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
208 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
209 | } | |
210 | ||
211 | /** | |
212 | * Test civicrm_group_organization_remove with empty params. | |
213 | */ | |
214 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
2d34d4bb | 215 | $params = array( ); |
d0e1eff2 | 216 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
217 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
218 | } | |
219 | ||
220 | /** | |
221 | * Test civicrm_group_organization_remove with valid params. | |
222 | */ | |
223 | public function testGroupOrganizationDelete() { | |
224 | $paramsC = array( | |
225 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 226 | 'group_id' => $this->_groupID, ); |
227 | $result = $this->callAPISuccess('group_organization', 'create', $paramsC); | |
6a488035 TO |
228 | |
229 | $params = array( | |
230 | 'id' => $result['id'], | |
6a488035 | 231 | ); |
2d34d4bb | 232 | $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
233 | } |
234 | ||
235 | /** | |
236 | * Test civicrm_group_organization_remove with invalid params key. | |
237 | */ | |
238 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
239 | $paramsDelete = array( | |
2d34d4bb | 240 | 'invalid_key' => 1, ); |
d0e1eff2 | 241 | $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); |
6a488035 TO |
242 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
243 | } | |
244 | } | |
245 |