3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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;
41 'name' => 'Group Organization',
42 'description' => 'Test all Group Organization API methods.',
43 'group' => 'CiviCRM API Tests',
48 * Sets up the fixture, for example, opens a network connection.
49 * This method is called before a test is executed.
53 protected function setUp() {
54 $this->_apiversion
= 3;
56 $this->_groupID
= $this->groupCreate();
58 $this->_orgID
= $this->organizationCreate(NULL);
62 * Tears down the fixture, for example, closes a network connection.
63 * This method is called after a test is executed.
67 protected function tearDown() {
68 // Truncate the tables
72 'civicrm_group_organization',
81 ///////////////// civicrm_group_organization_get methods
84 * Test civicrm_group_organization_get with valid params.
86 public function testGroupOrganizationGet() {
89 'organization_id' => $this->_orgID
,
90 'group_id' => $this->_groupID
, );
91 $result = $this->callAPISuccess('group_organization', 'create', $params);
93 'organization_id' => $result['id'],
95 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
99 * Test civicrm_group_organization_get with group_id.
101 public function testGroupOrganizationGetWithGroupId() {
104 'organization_id' => $this->_orgID
,
105 'group_id' => $this->_groupID
, 'sequential' => 1,
107 $result = $this->callAPISuccess('group_organization', 'create', $params);
109 $paramsGet = array('organization_id' => $result['values'][0]['organization_id']);
111 $result = $this->callAPISuccess('group_organization', 'get', $params);
112 $this->assertAPISuccess($result);
116 * Test civicrm_group_organization_get with empty params.
118 public function testGroupOrganizationGetWithEmptyParams() {
120 $result = $this->callAPISuccess('group_organization', 'get', $params);
122 $this->assertAPISuccess($result);
126 * Test civicrm_group_organization_get with wrong params.
128 public function testGroupOrganizationGetWithWrongParams() {
129 $params = 'groupOrg';
130 $result = $this->callAPIFailure('group_organization', 'get', $params);
131 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
135 * Test civicrm_group_organization_get invalid keys.
137 public function testGroupOrganizationGetWithInvalidKeys() {
139 'invalid_key' => 1, );
140 $result = $this->callAPISuccess('group_organization', 'get', $params);
142 $this->assertAPISuccess($result);
145 ///////////////// civicrm_group_organization_create methods
148 * check with valid params
150 public function testGroupOrganizationCreate() {
152 'organization_id' => $this->_orgID
,
153 'group_id' => $this->_groupID
, );
154 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
158 * CRM-13841 - Load Group Org before save
160 public function testGroupOrganizationCreateTwice() {
162 'organization_id' => $this->_orgID
,
163 'group_id' => $this->_groupID
, );
164 $result = $this->callAPISuccess('group_organization', 'create', $params);
165 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
166 $this->assertEquals($result['values'], $result2['values']);
169 * check with empty params array
171 public function testGroupOrganizationCreateWithEmptyParams() {
173 $result = $this->callAPIFailure('group_organization', 'create', $params);
174 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
178 * check with invalid params
180 public function testGroupOrganizationCreateParamsNotArray() {
181 $params = 'group_org';
182 $result = $this->callAPIFailure('group_organization', 'create', $params);
183 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
187 * check with invalid params keys
189 public function testGroupOrganizationCreateWithInvalidKeys() {
191 'invalid_key' => 1, );
192 $result = $this->callAPIFailure('group_organization', 'create', $params);
193 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
196 ///////////////// civicrm_group_organization_remove methods
199 * Test civicrm_group_organization_remove with params not an array.
201 public function testGroupOrganizationDeleteParamsNotArray() {
203 $result = $this->callAPIFailure('group_organization', 'delete', $params);
204 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
208 * Test civicrm_group_organization_remove with empty params.
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 public function testGroupOrganizationDelete() {
221 'organization_id' => $this->_orgID
,
222 'group_id' => $this->_groupID
, );
223 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
226 'id' => $result['id'],
228 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
232 * Test civicrm_group_organization_remove with invalid params key.
234 public function testGroupOrganizationDeleteWithInvalidKey() {
235 $paramsDelete = array(
236 'invalid_key' => 1, );
237 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
238 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');