3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 public function testGroupOrganizationGet() {
58 'organization_id' => $this->_orgID
,
59 'group_id' => $this->_groupID
,
61 $result = $this->callAPISuccess('group_organization', 'create', $params);
63 'organization_id' => $result['id'],
65 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
69 * Test civicrm_group_organization_get with group_id.
71 public function testGroupOrganizationGetWithGroupId() {
72 $createParams = array(
73 'organization_id' => $this->_orgID
,
74 'group_id' => $this->_groupID
,
76 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
79 'group_id' => $this->_groupID
,
82 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
83 $this->assertEquals($createResult['values'], $getResult['values'][0]);
87 * Test civicrm_group_organization_get with empty params.
89 public function testGroupOrganizationGetWithEmptyParams() {
91 $result = $this->callAPISuccess('group_organization', 'get', $params);
93 $this->assertAPISuccess($result);
97 * Test civicrm_group_organization_get with wrong params.
99 public function testGroupOrganizationGetWithWrongParams() {
100 $params = 'groupOrg';
101 $result = $this->callAPIFailure('group_organization', 'get', $params);
102 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
106 * Test civicrm_group_organization_get invalid keys.
108 public function testGroupOrganizationGetWithInvalidKeys() {
112 $result = $this->callAPISuccess('group_organization', 'get', $params);
114 $this->assertAPISuccess($result);
117 ///////////////// civicrm_group_organization_create methods
120 * Check with valid params.
122 public function testGroupOrganizationCreate() {
124 'organization_id' => $this->_orgID
,
125 'group_id' => $this->_groupID
,
127 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
131 * CRM-13841 - Load Group Org before save
133 public function testGroupOrganizationCreateTwice() {
135 'organization_id' => $this->_orgID
,
136 'group_id' => $this->_groupID
,
138 $result = $this->callAPISuccess('group_organization', 'create', $params);
139 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
140 $this->assertEquals($result['values'], $result2['values']);
144 * Check with empty params array.
146 public function testGroupOrganizationCreateWithEmptyParams() {
148 $result = $this->callAPIFailure('group_organization', 'create', $params);
149 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
153 * Check with invalid params.
155 public function testGroupOrganizationCreateParamsNotArray() {
156 $params = 'group_org';
157 $result = $this->callAPIFailure('group_organization', 'create', $params);
158 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
162 * Check with invalid params keys.
164 public function testGroupOrganizationCreateWithInvalidKeys() {
168 $result = $this->callAPIFailure('group_organization', 'create', $params);
169 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
172 ///////////////// civicrm_group_organization_remove methods
175 * Test civicrm_group_organization_remove with params not an array.
177 public function testGroupOrganizationDeleteParamsNotArray() {
179 $result = $this->callAPIFailure('group_organization', 'delete', $params);
180 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
184 * Test civicrm_group_organization_remove with empty params.
186 public function testGroupOrganizationDeleteWithEmptyParams() {
188 $result = $this->callAPIFailure('group_organization', 'delete', $params);
189 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
193 * Test civicrm_group_organization_remove with valid params.
195 public function testGroupOrganizationDelete() {
197 'organization_id' => $this->_orgID
,
198 'group_id' => $this->_groupID
,
200 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
203 'id' => $result['id'],
205 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
209 * Test civicrm_group_organization_remove with invalid params key.
211 public function testGroupOrganizationDeleteWithInvalidKey() {
212 $paramsDelete = array(
215 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
216 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');