3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test class for GroupOrganization API - civicrm_group_organization_*
34 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
38 * Sets up the fixture, for example, opens a network connection.
39 * This method is called before a test is executed.
41 protected function setUp() {
42 $this->_apiversion
= 3;
44 $this->useTransaction(TRUE);
45 $this->_groupID
= $this->groupCreate();
47 $this->_orgID
= $this->organizationCreate(NULL);
50 ///////////////// civicrm_group_organization_get methods
53 * Test civicrm_group_organization_get with valid params.
55 * @dataProvider versionThreeAndFour
57 public function testGroupOrganizationGet() {
60 'organization_id' => $this->_orgID
,
61 'group_id' => $this->_groupID
,
63 $result = $this->callAPISuccess('group_organization', 'create', $params);
65 'organization_id' => $result['id'],
67 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
71 * Test civicrm_group_organization_get with group_id.
73 * @dataProvider versionThreeAndFour
75 public function testGroupOrganizationGetWithGroupId() {
77 'organization_id' => $this->_orgID
,
78 'group_id' => $this->_groupID
,
80 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
83 'group_id' => $this->_groupID
,
86 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
87 $this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]);
91 * Test civicrm_group_organization_get with empty params.
93 * @dataProvider versionThreeAndFour
95 public function testGroupOrganizationGetWithEmptyParams() {
97 $result = $this->callAPISuccess('group_organization', 'get', $params);
99 $this->assertAPISuccess($result);
103 * Test civicrm_group_organization_get with wrong params.
105 * @dataProvider versionThreeAndFour
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');
114 * Test civicrm_group_organization_get invalid keys.
116 * @dataProvider versionThreeAndFour
118 public function testGroupOrganizationGetWithInvalidKeys() {
122 $result = $this->callAPISuccess('group_organization', 'get', $params);
124 $this->assertAPISuccess($result);
127 ///////////////// civicrm_group_organization_create methods
130 * Check with valid params.
132 * @dataProvider versionThreeAndFour
134 public function testGroupOrganizationCreate() {
136 'organization_id' => $this->_orgID
,
137 'group_id' => $this->_groupID
,
139 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
143 * CRM-13841 - Load Group Org before save
145 * @dataProvider versionThreeAndFour
147 public function testGroupOrganizationCreateTwice() {
149 'organization_id' => $this->_orgID
,
150 'group_id' => $this->_groupID
,
152 $result = $this->callAPISuccess('group_organization', 'create', $params);
153 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
154 $this->assertEquals($result['values'], $result2['values']);
158 * Check with empty params array.
160 * @dataProvider versionThreeAndFour
162 public function testGroupOrganizationCreateWithEmptyParams() {
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');
169 * Check with invalid params.
171 * @dataProvider versionThreeAndFour
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');
180 * Check with invalid params keys.
182 * @dataProvider versionThreeAndFour
184 public function testGroupOrganizationCreateWithInvalidKeys() {
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');
192 ///////////////// civicrm_group_organization_remove methods
195 * Test civicrm_group_organization_remove with params not an array.
197 * @dataProvider versionThreeAndFour
199 public function testGroupOrganizationDeleteParamsNotArray() {
201 $result = $this->callAPIFailure('group_organization', 'delete', $params);
202 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
206 * Test civicrm_group_organization_remove with empty params.
208 * @dataProvider versionThreeAndFour
210 public function testGroupOrganizationDeleteWithEmptyParams() {
212 $result = $this->callAPIFailure('group_organization', 'delete', $params);
213 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
217 * Test civicrm_group_organization_remove with valid params.
219 * @dataProvider versionThreeAndFour
221 public function testGroupOrganizationDelete() {
223 'organization_id' => $this->_orgID
,
224 'group_id' => $this->_groupID
,
226 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
229 'id' => $result['id'],
231 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
235 * Test civicrm_group_organization_remove with invalid params key.
237 * @dataProvider versionThreeAndFour
239 public function testGroupOrganizationDeleteWithInvalidKey() {
243 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
244 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');