Merge pull request #15329 from mattwire/contributepagetab_cleanupstatic
[civicrm-core.git] / tests / phpunit / api / v3 / GroupOrganizationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 /**
29 * Test class for GroupOrganization API - civicrm_group_organization_*
30 *
31 * @package CiviCRM
32 * @group headless
33 */
34 class api_v3_GroupOrganizationTest extends CiviUnitTestCase {
35 protected $_apiversion;
36
37 /**
38 * Sets up the fixture, for example, opens a network connection.
39 * This method is called before a test is executed.
40 */
41 protected function setUp() {
42 $this->_apiversion = 3;
43 parent::setUp();
44 $this->useTransaction(TRUE);
45 $this->_groupID = $this->groupCreate();
46
47 $this->_orgID = $this->organizationCreate(NULL);
48 }
49
50 ///////////////// civicrm_group_organization_get methods
51
52 /**
53 * Test civicrm_group_organization_get with valid params.
54 *
55 * @dataProvider versionThreeAndFour
56 */
57 public function testGroupOrganizationGet() {
58
59 $params = [
60 'organization_id' => $this->_orgID,
61 'group_id' => $this->_groupID,
62 ];
63 $result = $this->callAPISuccess('group_organization', 'create', $params);
64 $paramsGet = [
65 'organization_id' => $result['id'],
66 ];
67 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__);
68 }
69
70 /**
71 * Test civicrm_group_organization_get with group_id.
72 *
73 * @dataProvider versionThreeAndFour
74 */
75 public function testGroupOrganizationGetWithGroupId() {
76 $createParams = [
77 'organization_id' => $this->_orgID,
78 'group_id' => $this->_groupID,
79 ];
80 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
81
82 $getParams = [
83 'group_id' => $this->_groupID,
84 'sequential' => 1,
85 ];
86 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
87 $this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]);
88 }
89
90 /**
91 * Test civicrm_group_organization_get with empty params.
92 *
93 * @dataProvider versionThreeAndFour
94 */
95 public function testGroupOrganizationGetWithEmptyParams() {
96 $params = [];
97 $result = $this->callAPISuccess('group_organization', 'get', $params);
98
99 $this->assertAPISuccess($result);
100 }
101
102 /**
103 * Test civicrm_group_organization_get with wrong params.
104 *
105 * @dataProvider versionThreeAndFour
106 */
107 public function testGroupOrganizationGetWithWrongParams() {
108 $params = 'groupOrg';
109 $result = $this->callAPIFailure('group_organization', 'get', $params);
110 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
111 }
112
113 /**
114 * Test civicrm_group_organization_get invalid keys.
115 *
116 * @dataProvider versionThreeAndFour
117 */
118 public function testGroupOrganizationGetWithInvalidKeys() {
119 $params = [
120 'invalid_key' => 1,
121 ];
122 $result = $this->callAPISuccess('group_organization', 'get', $params);
123
124 $this->assertAPISuccess($result);
125 }
126
127 ///////////////// civicrm_group_organization_create methods
128
129 /**
130 * Check with valid params.
131 *
132 * @dataProvider versionThreeAndFour
133 */
134 public function testGroupOrganizationCreate() {
135 $params = [
136 'organization_id' => $this->_orgID,
137 'group_id' => $this->_groupID,
138 ];
139 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__);
140 }
141
142 /**
143 * CRM-13841 - Load Group Org before save
144 *
145 * @dataProvider versionThreeAndFour
146 */
147 public function testGroupOrganizationCreateTwice() {
148 $params = [
149 'organization_id' => $this->_orgID,
150 'group_id' => $this->_groupID,
151 ];
152 $result = $this->callAPISuccess('group_organization', 'create', $params);
153 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
154 $this->assertEquals($result['values'], $result2['values']);
155 }
156
157 /**
158 * Check with empty params array.
159 *
160 * @dataProvider versionThreeAndFour
161 */
162 public function testGroupOrganizationCreateWithEmptyParams() {
163 $params = [];
164 $result = $this->callAPIFailure('group_organization', 'create', $params);
165 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
166 }
167
168 /**
169 * Check with invalid params.
170 *
171 * @dataProvider versionThreeAndFour
172 */
173 public function testGroupOrganizationCreateParamsNotArray() {
174 $params = 'group_org';
175 $result = $this->callAPIFailure('group_organization', 'create', $params);
176 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
177 }
178
179 /**
180 * Check with invalid params keys.
181 *
182 * @dataProvider versionThreeAndFour
183 */
184 public function testGroupOrganizationCreateWithInvalidKeys() {
185 $params = [
186 'invalid_key' => 1,
187 ];
188 $result = $this->callAPIFailure('group_organization', 'create', $params);
189 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
190 }
191
192 ///////////////// civicrm_group_organization_remove methods
193
194 /**
195 * Test civicrm_group_organization_remove with params not an array.
196 *
197 * @dataProvider versionThreeAndFour
198 */
199 public function testGroupOrganizationDeleteParamsNotArray() {
200 $params = 'delete';
201 $result = $this->callAPIFailure('group_organization', 'delete', $params);
202 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
203 }
204
205 /**
206 * Test civicrm_group_organization_remove with empty params.
207 *
208 * @dataProvider versionThreeAndFour
209 */
210 public function testGroupOrganizationDeleteWithEmptyParams() {
211 $params = [];
212 $result = $this->callAPIFailure('group_organization', 'delete', $params);
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 * @dataProvider versionThreeAndFour
220 */
221 public function testGroupOrganizationDelete() {
222 $paramsC = [
223 'organization_id' => $this->_orgID,
224 'group_id' => $this->_groupID,
225 ];
226 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
227
228 $params = [
229 'id' => $result['id'],
230 ];
231 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__);
232 }
233
234 /**
235 * Test civicrm_group_organization_remove with invalid params key.
236 *
237 * @dataProvider versionThreeAndFour
238 */
239 public function testGroupOrganizationDeleteWithInvalidKey() {
240 $paramsDelete = [
241 'invalid_key' => 1,
242 ];
243 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
244 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
245 }
246
247 }