3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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;
44 'name' => 'Group Organization',
45 'description' => 'Test all Group Organization API methods.',
46 'group' => 'CiviCRM API Tests',
51 * Sets up the fixture, for example, opens a network connection.
52 * This method is called before a test is executed.
56 protected function setUp() {
57 $this->_apiversion
= 3;
59 $this->_groupID
= $this->groupCreate();
61 $this->_orgID
= $this->organizationCreate(NULL);
65 * Tears down the fixture, for example, closes a network connection.
66 * This method is called after a test is executed.
70 protected function tearDown() {
71 // Truncate the tables
75 'civicrm_group_organization',
84 ///////////////// civicrm_group_organization_get methods
87 * Test civicrm_group_organization_get with valid params.
89 public function testGroupOrganizationGet() {
92 'organization_id' => $this->_orgID
,
93 'group_id' => $this->_groupID
, );
94 $result = $this->callAPISuccess('group_organization', 'create', $params);
96 'organization_id' => $result['id'],
98 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
102 * Test civicrm_group_organization_get with group_id.
104 public function testGroupOrganizationGetWithGroupId() {
105 $createParams = array(
106 'organization_id' => $this->_orgID
,
107 'group_id' => $this->_groupID
,
109 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
112 'group_id' => $this->_groupID
,
115 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
116 $this->assertEquals($createResult['values'], $getResult['values'][0]);
120 * Test civicrm_group_organization_get with empty params.
122 public function testGroupOrganizationGetWithEmptyParams() {
124 $result = $this->callAPISuccess('group_organization', 'get', $params);
126 $this->assertAPISuccess($result);
130 * Test civicrm_group_organization_get with wrong params.
132 public function testGroupOrganizationGetWithWrongParams() {
133 $params = 'groupOrg';
134 $result = $this->callAPIFailure('group_organization', 'get', $params);
135 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
139 * Test civicrm_group_organization_get invalid keys.
141 public function testGroupOrganizationGetWithInvalidKeys() {
143 'invalid_key' => 1, );
144 $result = $this->callAPISuccess('group_organization', 'get', $params);
146 $this->assertAPISuccess($result);
149 ///////////////// civicrm_group_organization_create methods
152 * Check with valid params
154 public function testGroupOrganizationCreate() {
156 'organization_id' => $this->_orgID
,
157 'group_id' => $this->_groupID
, );
158 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
162 * CRM-13841 - Load Group Org before save
164 public function testGroupOrganizationCreateTwice() {
166 'organization_id' => $this->_orgID
,
167 'group_id' => $this->_groupID
, );
168 $result = $this->callAPISuccess('group_organization', 'create', $params);
169 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
170 $this->assertEquals($result['values'], $result2['values']);
173 * Check with empty params array
175 public function testGroupOrganizationCreateWithEmptyParams() {
177 $result = $this->callAPIFailure('group_organization', 'create', $params);
178 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
182 * Check with invalid params
184 public function testGroupOrganizationCreateParamsNotArray() {
185 $params = 'group_org';
186 $result = $this->callAPIFailure('group_organization', 'create', $params);
187 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
191 * Check with invalid params keys
193 public function testGroupOrganizationCreateWithInvalidKeys() {
195 'invalid_key' => 1, );
196 $result = $this->callAPIFailure('group_organization', 'create', $params);
197 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
200 ///////////////// civicrm_group_organization_remove methods
203 * Test civicrm_group_organization_remove with params not an array.
205 public function testGroupOrganizationDeleteParamsNotArray() {
207 $result = $this->callAPIFailure('group_organization', 'delete', $params);
208 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
212 * Test civicrm_group_organization_remove with empty params.
214 public function testGroupOrganizationDeleteWithEmptyParams() {
216 $result = $this->callAPIFailure('group_organization', 'delete', $params);
217 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
221 * Test civicrm_group_organization_remove with valid params.
223 public function testGroupOrganizationDelete() {
225 'organization_id' => $this->_orgID
,
226 'group_id' => $this->_groupID
, );
227 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
230 'id' => $result['id'],
232 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
236 * Test civicrm_group_organization_remove with invalid params key.
238 public function testGroupOrganizationDeleteWithInvalidKey() {
239 $paramsDelete = array(
240 'invalid_key' => 1, );
241 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
242 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');