3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test class for GroupOrganization API - civicrm_group_organization_*
36 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
43 protected function setUp() {
44 $this->_apiversion
= 3;
46 $this->useTransaction(TRUE);
47 $this->_groupID
= $this->groupCreate();
49 $this->_orgID
= $this->organizationCreate(NULL);
52 ///////////////// civicrm_group_organization_get methods
55 * Test civicrm_group_organization_get with valid params.
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 public function testGroupOrganizationGetWithGroupId() {
74 $createParams = array(
75 'organization_id' => $this->_orgID
,
76 'group_id' => $this->_groupID
,
78 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
81 'group_id' => $this->_groupID
,
84 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
85 $this->assertEquals($createResult['values'], $getResult['values'][0]);
89 * Test civicrm_group_organization_get with empty params.
91 public function testGroupOrganizationGetWithEmptyParams() {
93 $result = $this->callAPISuccess('group_organization', 'get', $params);
95 $this->assertAPISuccess($result);
99 * Test civicrm_group_organization_get with wrong params.
101 public function testGroupOrganizationGetWithWrongParams() {
102 $params = 'groupOrg';
103 $result = $this->callAPIFailure('group_organization', 'get', $params);
104 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
108 * Test civicrm_group_organization_get invalid keys.
110 public function testGroupOrganizationGetWithInvalidKeys() {
114 $result = $this->callAPISuccess('group_organization', 'get', $params);
116 $this->assertAPISuccess($result);
119 ///////////////// civicrm_group_organization_create methods
122 * Check with valid params
124 public function testGroupOrganizationCreate() {
126 'organization_id' => $this->_orgID
,
127 'group_id' => $this->_groupID
,
129 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
133 * CRM-13841 - Load Group Org before save
135 public function testGroupOrganizationCreateTwice() {
137 'organization_id' => $this->_orgID
,
138 'group_id' => $this->_groupID
,
140 $result = $this->callAPISuccess('group_organization', 'create', $params);
141 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
142 $this->assertEquals($result['values'], $result2['values']);
146 * Check with empty params array
148 public function testGroupOrganizationCreateWithEmptyParams() {
150 $result = $this->callAPIFailure('group_organization', 'create', $params);
151 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
155 * Check with invalid params
157 public function testGroupOrganizationCreateParamsNotArray() {
158 $params = 'group_org';
159 $result = $this->callAPIFailure('group_organization', 'create', $params);
160 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
164 * Check with invalid params keys
166 public function testGroupOrganizationCreateWithInvalidKeys() {
170 $result = $this->callAPIFailure('group_organization', 'create', $params);
171 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
174 ///////////////// civicrm_group_organization_remove methods
177 * Test civicrm_group_organization_remove with params not an array.
179 public function testGroupOrganizationDeleteParamsNotArray() {
181 $result = $this->callAPIFailure('group_organization', 'delete', $params);
182 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
186 * Test civicrm_group_organization_remove with empty params.
188 public function testGroupOrganizationDeleteWithEmptyParams() {
190 $result = $this->callAPIFailure('group_organization', 'delete', $params);
191 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
195 * Test civicrm_group_organization_remove with valid params.
197 public function testGroupOrganizationDelete() {
199 'organization_id' => $this->_orgID
,
200 'group_id' => $this->_groupID
,
202 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
205 'id' => $result['id'],
207 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
211 * Test civicrm_group_organization_remove with invalid params key.
213 public function testGroupOrganizationDeleteWithInvalidKey() {
214 $paramsDelete = array(
217 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
218 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');