Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 TO |
38 | |
39 | function get_info() { | |
40 | return array( | |
41 | 'name' => 'Group Organization', | |
42 | 'description' => 'Test all Group Organization API methods.', | |
43 | 'group' => 'CiviCRM API Tests', | |
44 | ); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Sets up the fixture, for example, opens a network connection. | |
49 | * This method is called before a test is executed. | |
50 | * | |
51 | * @access protected | |
52 | */ | |
53 | protected function setUp() { | |
54 | $this->_apiversion = 3; | |
55 | parent::setUp(); | |
fadb804f | 56 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
57 | |
58 | $this->_orgID = $this->organizationCreate(NULL); | |
59 | } | |
60 | ||
61 | /** | |
62 | * Tears down the fixture, for example, closes a network connection. | |
63 | * This method is called after a test is executed. | |
64 | * | |
65 | * @access protected | |
66 | */ | |
67 | protected function tearDown() { | |
68 | // Truncate the tables | |
69 | $this->quickCleanup( | |
70 | array( | |
71 | 'civicrm_group', | |
72 | 'civicrm_group_organization', | |
73 | 'civicrm_contact', | |
74 | 'civicrm_uf_group', | |
75 | 'civicrm_uf_join', | |
76 | 'civicrm_uf_match', | |
77 | ) | |
78 | ); | |
79 | } | |
80 | ||
81 | ///////////////// civicrm_group_organization_get methods | |
82 | ||
83 | /** | |
84 | * Test civicrm_group_organization_get with valid params. | |
85 | */ | |
86 | public function testGroupOrganizationGet() { | |
87 | ||
88 | $params = array( | |
89 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 90 | 'group_id' => $this->_groupID, ); |
91 | $result = $this->callAPISuccess('group_organization', 'create', $params); | |
6a488035 TO |
92 | $paramsGet = array( |
93 | 'organization_id' => $result['id'], | |
6a488035 | 94 | ); |
2d34d4bb | 95 | $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); |
6a488035 TO |
96 | } |
97 | ||
98 | /** | |
99 | * Test civicrm_group_organization_get with group_id. | |
100 | */ | |
101 | public function testGroupOrganizationGetWithGroupId() { | |
102 | ||
103 | $params = array( | |
104 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 105 | 'group_id' => $this->_groupID, 'sequential' => 1, |
6a488035 | 106 | ); |
2d34d4bb | 107 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
6a488035 TO |
108 | |
109 | $paramsGet = array('organization_id' => $result['values'][0]['organization_id']); | |
110 | ||
2d34d4bb | 111 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
791c263c | 112 | $this->assertAPISuccess($result); |
6a488035 TO |
113 | } |
114 | ||
115 | /** | |
116 | * Test civicrm_group_organization_get with empty params. | |
117 | */ | |
118 | public function testGroupOrganizationGetWithEmptyParams() { | |
2d34d4bb | 119 | $params = array( ); |
120 | $result = $this->callAPISuccess('group_organization', 'get', $params); | |
6a488035 | 121 | |
791c263c | 122 | $this->assertAPISuccess($result); |
6a488035 TO |
123 | } |
124 | ||
125 | /** | |
126 | * Test civicrm_group_organization_get with wrong params. | |
127 | */ | |
128 | public function testGroupOrganizationGetWithWrongParams() { | |
129 | $params = 'groupOrg'; | |
d0e1eff2 | 130 | $result = $this->callAPIFailure('group_organization', 'get', $params); |
6a488035 TO |
131 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
132 | } | |
133 | ||
134 | /** | |
135 | * Test civicrm_group_organization_get invalid keys. | |
136 | */ | |
137 | public function testGroupOrganizationGetWithInvalidKeys() { | |
138 | $params = array( | |
2d34d4bb | 139 | 'invalid_key' => 1, ); |
140 | $result = $this->callAPISuccess('group_organization', 'get', $params); | |
6a488035 | 141 | |
791c263c | 142 | $this->assertAPISuccess($result); |
6a488035 TO |
143 | } |
144 | ||
145 | ///////////////// civicrm_group_organization_create methods | |
146 | ||
147 | /** | |
148 | * check with valid params | |
149 | */ | |
150 | public function testGroupOrganizationCreate() { | |
151 | $params = array( | |
152 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 153 | 'group_id' => $this->_groupID, ); |
154 | $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
155 | } |
156 | ||
c69fdfbb E |
157 | /** |
158 | * CRM-13841 - Load Group Org before save | |
159 | */ | |
160 | public function testGroupOrganizationCreateTwice() { | |
161 | $params = array( | |
162 | 'organization_id' => $this->_orgID, | |
163 | 'group_id' => $this->_groupID, ); | |
164 | $result = $this->callAPISuccess('group_organization', 'create', $params); | |
165 | $result2 = $this->callAPISuccess('group_organization', 'create', $params); | |
166 | $this->assertEquals($result['values'], $result2['values']); | |
167 | } | |
6a488035 TO |
168 | /** |
169 | * check with empty params array | |
170 | */ | |
171 | public function testGroupOrganizationCreateWithEmptyParams() { | |
2d34d4bb | 172 | $params = array( ); |
d0e1eff2 | 173 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
174 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
175 | } | |
176 | ||
177 | /** | |
178 | * check with invalid params | |
179 | */ | |
180 | public function testGroupOrganizationCreateParamsNotArray() { | |
181 | $params = 'group_org'; | |
d0e1eff2 | 182 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
183 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
184 | } | |
185 | ||
186 | /** | |
187 | * check with invalid params keys | |
188 | */ | |
189 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
190 | $params = array( | |
2d34d4bb | 191 | 'invalid_key' => 1, ); |
d0e1eff2 | 192 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
193 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
194 | } | |
195 | ||
196 | ///////////////// civicrm_group_organization_remove methods | |
197 | ||
198 | /** | |
199 | * Test civicrm_group_organization_remove with params not an array. | |
200 | */ | |
201 | public function testGroupOrganizationDeleteParamsNotArray() { | |
202 | $params = 'delete'; | |
d0e1eff2 | 203 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
204 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
205 | } | |
206 | ||
207 | /** | |
208 | * Test civicrm_group_organization_remove with empty params. | |
209 | */ | |
210 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
2d34d4bb | 211 | $params = array( ); |
d0e1eff2 | 212 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
213 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
214 | } | |
215 | ||
216 | /** | |
217 | * Test civicrm_group_organization_remove with valid params. | |
218 | */ | |
219 | public function testGroupOrganizationDelete() { | |
220 | $paramsC = array( | |
221 | 'organization_id' => $this->_orgID, | |
2d34d4bb | 222 | 'group_id' => $this->_groupID, ); |
223 | $result = $this->callAPISuccess('group_organization', 'create', $paramsC); | |
6a488035 TO |
224 | |
225 | $params = array( | |
226 | 'id' => $result['id'], | |
6a488035 | 227 | ); |
2d34d4bb | 228 | $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
229 | } |
230 | ||
231 | /** | |
232 | * Test civicrm_group_organization_remove with invalid params key. | |
233 | */ | |
234 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
235 | $paramsDelete = array( | |
2d34d4bb | 236 | 'invalid_key' => 1, ); |
d0e1eff2 | 237 | $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); |
6a488035 TO |
238 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
239 | } | |
240 | } | |
241 |