4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
33 * Test class for GroupOrganization API - civicrm_group_organization_*
37 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
38 protected $_apiversion;
39 public $_eNoticeCompliant = True;
43 'name' => 'Group Organization',
44 'description' => 'Test all Group Organization API methods.',
45 'group' => 'CiviCRM API Tests',
50 * Sets up the fixture, for example, opens a network connection.
51 * This method is called before a test is executed.
55 protected function setUp() {
56 $this->_apiversion
= 3;
58 $this->_groupID
= $this->groupCreate(NULL);
60 $this->_orgID
= $this->organizationCreate(NULL);
64 * Tears down the fixture, for example, closes a network connection.
65 * This method is called after a test is executed.
69 protected function tearDown() {
70 // Truncate the tables
74 'civicrm_group_organization',
83 ///////////////// civicrm_group_organization_get methods
86 * Test civicrm_group_organization_get with valid params.
88 public function testGroupOrganizationGet() {
91 'organization_id' => $this->_orgID
,
92 'group_id' => $this->_groupID
,
93 'version' => $this->_apiversion
,
95 $result = civicrm_api('group_organization', 'create', $params);
97 'organization_id' => $result['id'],
98 'version' => $this->_apiversion
,
100 $result = civicrm_api('group_organization', 'get', $paramsGet);
101 $this->documentMe($paramsGet, $result, __FUNCTION__
, __FILE__
);
102 $this->assertAPISuccess($result);
106 * Test civicrm_group_organization_get with group_id.
108 public function testGroupOrganizationGetWithGroupId() {
111 'organization_id' => $this->_orgID
,
112 'group_id' => $this->_groupID
,
113 'version' => $this->_apiversion
,
116 $result = civicrm_api('group_organization', 'create', $params);
118 $paramsGet = array('organization_id' => $result['values'][0]['organization_id']);
120 $result = civicrm_api('group_organization', 'get', $params);
121 $this->assertAPISuccess($result);
125 * Test civicrm_group_organization_get with empty params.
127 public function testGroupOrganizationGetWithEmptyParams() {
129 'version' => $this->_apiversion
,
131 $result = civicrm_api('group_organization', 'get', $params);
133 $this->assertAPISuccess($result);
137 * Test civicrm_group_organization_get with wrong params.
139 public function testGroupOrganizationGetWithWrongParams() {
140 $params = 'groupOrg';
141 $result = $this->callAPIFailure('group_organization', 'get', $params);
142 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
146 * Test civicrm_group_organization_get invalid keys.
148 public function testGroupOrganizationGetWithInvalidKeys() {
151 'version' => $this->_apiversion
,
153 $result = civicrm_api('group_organization', 'get', $params);
155 $this->assertAPISuccess($result);
158 ///////////////// civicrm_group_organization_create methods
161 * check with valid params
163 public function testGroupOrganizationCreate() {
165 'organization_id' => $this->_orgID
,
166 'group_id' => $this->_groupID
,
167 'version' => $this->_apiversion
,
169 $result = civicrm_api('group_organization', 'create', $params);
170 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
171 $this->assertAPISuccess($result, "in line " . __LINE__
);
175 * check with empty params array
177 public function testGroupOrganizationCreateWithEmptyParams() {
179 'version' => $this->_apiversion
,
181 $result = $this->callAPIFailure('group_organization', 'create', $params);
182 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
186 * check with invalid params
188 public function testGroupOrganizationCreateParamsNotArray() {
189 $params = 'group_org';
190 $result = $this->callAPIFailure('group_organization', 'create', $params);
191 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
195 * check with invalid params keys
197 public function testGroupOrganizationCreateWithInvalidKeys() {
200 'version' => $this->_apiversion
,
202 $result = $this->callAPIFailure('group_organization', 'create', $params);
203 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
206 ///////////////// civicrm_group_organization_remove methods
209 * Test civicrm_group_organization_remove with params not an array.
211 public function testGroupOrganizationDeleteParamsNotArray() {
213 $result = $this->callAPIFailure('group_organization', 'delete', $params);
214 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
218 * Test civicrm_group_organization_remove with empty params.
220 public function testGroupOrganizationDeleteWithEmptyParams() {
222 'version' => $this->_apiversion
,
224 $result = $this->callAPIFailure('group_organization', 'delete', $params);
225 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
229 * Test civicrm_group_organization_remove with valid params.
231 public function testGroupOrganizationDelete() {
233 'organization_id' => $this->_orgID
,
234 'group_id' => $this->_groupID
,
235 'version' => $this->_apiversion
,
237 $result = civicrm_api('group_organization', 'create', $paramsC);
240 'id' => $result['id'],
241 'version' => $this->_apiversion
,
243 $result = civicrm_api('group_organization', 'delete', $params);
244 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
245 $this->assertAPISuccess($result, "in line " . __LINE__
);
249 * Test civicrm_group_organization_remove with invalid params key.
251 public function testGroupOrganizationDeleteWithInvalidKey() {
252 $paramsDelete = array(
254 'version' => $this->_apiversion
,
256 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
257 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');