Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test class for GroupOrganization API - civicrm_group_organization_* | |
33 | * | |
6c6e6187 | 34 | * @package CiviCRM |
6a488035 TO |
35 | */ |
36 | class api_v3_GroupOrganizationTest extends CiviUnitTestCase { | |
37 | protected $_apiversion; | |
6a488035 | 38 | |
6a488035 TO |
39 | /** |
40 | * Sets up the fixture, for example, opens a network connection. | |
41 | * This method is called before a test is executed. | |
6a488035 TO |
42 | */ |
43 | protected function setUp() { | |
44 | $this->_apiversion = 3; | |
45 | parent::setUp(); | |
905d864b | 46 | $this->useTransaction(TRUE); |
fadb804f | 47 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
48 | |
49 | $this->_orgID = $this->organizationCreate(NULL); | |
50 | } | |
51 | ||
6a488035 TO |
52 | ///////////////// civicrm_group_organization_get methods |
53 | ||
54 | /** | |
55 | * Test civicrm_group_organization_get with valid params. | |
56 | */ | |
57 | public function testGroupOrganizationGet() { | |
58 | ||
59 | $params = array( | |
60 | 'organization_id' => $this->_orgID, | |
92915c55 TO |
61 | 'group_id' => $this->_groupID, |
62 | ); | |
2d34d4bb | 63 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
6a488035 TO |
64 | $paramsGet = array( |
65 | 'organization_id' => $result['id'], | |
6a488035 | 66 | ); |
2d34d4bb | 67 | $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); |
6a488035 TO |
68 | } |
69 | ||
70 | /** | |
71 | * Test civicrm_group_organization_get with group_id. | |
72 | */ | |
73 | public function testGroupOrganizationGetWithGroupId() { | |
25396471 | 74 | $createParams = array( |
6a488035 | 75 | 'organization_id' => $this->_orgID, |
25396471 | 76 | 'group_id' => $this->_groupID, |
6a488035 | 77 | ); |
25396471 | 78 | $createResult = $this->callAPISuccess('group_organization', 'create', $createParams); |
6a488035 | 79 | |
25396471 TO |
80 | $getParams = array( |
81 | 'group_id' => $this->_groupID, | |
82 | 'sequential' => 1, | |
83 | ); | |
84 | $getResult = $this->callAPISuccess('group_organization', 'get', $getParams); | |
85 | $this->assertEquals($createResult['values'], $getResult['values'][0]); | |
6a488035 TO |
86 | } |
87 | ||
88 | /** | |
89 | * Test civicrm_group_organization_get with empty params. | |
90 | */ | |
91 | public function testGroupOrganizationGetWithEmptyParams() { | |
6c6e6187 | 92 | $params = array(); |
2d34d4bb | 93 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 94 | |
791c263c | 95 | $this->assertAPISuccess($result); |
6a488035 TO |
96 | } |
97 | ||
98 | /** | |
99 | * Test civicrm_group_organization_get with wrong params. | |
100 | */ | |
101 | public function testGroupOrganizationGetWithWrongParams() { | |
102 | $params = 'groupOrg'; | |
d0e1eff2 | 103 | $result = $this->callAPIFailure('group_organization', 'get', $params); |
6a488035 TO |
104 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
105 | } | |
106 | ||
107 | /** | |
108 | * Test civicrm_group_organization_get invalid keys. | |
109 | */ | |
110 | public function testGroupOrganizationGetWithInvalidKeys() { | |
111 | $params = array( | |
92915c55 TO |
112 | 'invalid_key' => 1, |
113 | ); | |
2d34d4bb | 114 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 115 | |
791c263c | 116 | $this->assertAPISuccess($result); |
6a488035 TO |
117 | } |
118 | ||
119 | ///////////////// civicrm_group_organization_create methods | |
120 | ||
121 | /** | |
100fef9d | 122 | * Check with valid params |
6a488035 TO |
123 | */ |
124 | public function testGroupOrganizationCreate() { | |
125 | $params = array( | |
126 | 'organization_id' => $this->_orgID, | |
92915c55 TO |
127 | 'group_id' => $this->_groupID, |
128 | ); | |
2d34d4bb | 129 | $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
130 | } |
131 | ||
c69fdfbb E |
132 | /** |
133 | * CRM-13841 - Load Group Org before save | |
134 | */ | |
135 | public function testGroupOrganizationCreateTwice() { | |
136 | $params = array( | |
92915c55 TO |
137 | 'organization_id' => $this->_orgID, |
138 | 'group_id' => $this->_groupID, | |
139 | ); | |
c69fdfbb E |
140 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
141 | $result2 = $this->callAPISuccess('group_organization', 'create', $params); | |
142 | $this->assertEquals($result['values'], $result2['values']); | |
143 | } | |
92915c55 | 144 | |
6a488035 | 145 | /** |
100fef9d | 146 | * Check with empty params array |
6a488035 TO |
147 | */ |
148 | public function testGroupOrganizationCreateWithEmptyParams() { | |
6c6e6187 | 149 | $params = array(); |
d0e1eff2 | 150 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
151 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
152 | } | |
153 | ||
154 | /** | |
100fef9d | 155 | * Check with invalid params |
6a488035 TO |
156 | */ |
157 | public function testGroupOrganizationCreateParamsNotArray() { | |
158 | $params = 'group_org'; | |
d0e1eff2 | 159 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
160 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
161 | } | |
162 | ||
163 | /** | |
100fef9d | 164 | * Check with invalid params keys |
6a488035 TO |
165 | */ |
166 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
167 | $params = array( | |
92915c55 TO |
168 | 'invalid_key' => 1, |
169 | ); | |
d0e1eff2 | 170 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
171 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
172 | } | |
173 | ||
174 | ///////////////// civicrm_group_organization_remove methods | |
175 | ||
176 | /** | |
177 | * Test civicrm_group_organization_remove with params not an array. | |
178 | */ | |
179 | public function testGroupOrganizationDeleteParamsNotArray() { | |
180 | $params = 'delete'; | |
d0e1eff2 | 181 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
182 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
183 | } | |
184 | ||
185 | /** | |
186 | * Test civicrm_group_organization_remove with empty params. | |
187 | */ | |
188 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
6c6e6187 | 189 | $params = array(); |
d0e1eff2 | 190 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
191 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
192 | } | |
193 | ||
194 | /** | |
195 | * Test civicrm_group_organization_remove with valid params. | |
196 | */ | |
197 | public function testGroupOrganizationDelete() { | |
198 | $paramsC = array( | |
199 | 'organization_id' => $this->_orgID, | |
92915c55 TO |
200 | 'group_id' => $this->_groupID, |
201 | ); | |
2d34d4bb | 202 | $result = $this->callAPISuccess('group_organization', 'create', $paramsC); |
6a488035 TO |
203 | |
204 | $params = array( | |
205 | 'id' => $result['id'], | |
6a488035 | 206 | ); |
2d34d4bb | 207 | $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
208 | } |
209 | ||
210 | /** | |
211 | * Test civicrm_group_organization_remove with invalid params key. | |
212 | */ | |
213 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
214 | $paramsDelete = array( | |
92915c55 TO |
215 | 'invalid_key' => 1, |
216 | ); | |
d0e1eff2 | 217 | $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); |
6a488035 TO |
218 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
219 | } | |
96025800 | 220 | |
6a488035 | 221 | } |