5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
30 require_once 'CiviTest/CiviUnitTestCase.php';
34 * Test class for GroupOrganization API - civicrm_group_organization_*
38 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
39 protected $_apiversion;
40 public $_eNoticeCompliant = True;
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(NULL);
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 'version' => $this->_apiversion
,
96 $result = civicrm_api('group_organization', 'create', $params);
98 'organization_id' => $result['id'],
99 'version' => $this->_apiversion
,
101 $result = civicrm_api('group_organization', 'get', $paramsGet);
102 $this->documentMe($paramsGet, $result, __FUNCTION__
, __FILE__
);
103 $this->assertEquals($result['is_error'], 0);
107 * Test civicrm_group_organization_get with group_id.
109 public function testGroupOrganizationGetWithGroupId() {
112 'organization_id' => $this->_orgID
,
113 'group_id' => $this->_groupID
,
114 'version' => $this->_apiversion
,
117 $result = civicrm_api('group_organization', 'create', $params);
119 $paramsGet = array('organization_id' => $result['values'][0]['organization_id']);
121 $result = civicrm_api('group_organization', 'get', $params);
122 $this->assertEquals($result['is_error'], 0);
126 * Test civicrm_group_organization_get with empty params.
128 public function testGroupOrganizationGetWithEmptyParams() {
130 'version' => $this->_apiversion
,
132 $result = civicrm_api('group_organization', 'get', $params);
134 $this->assertEquals($result['is_error'], 0);
138 * Test civicrm_group_organization_get with wrong params.
140 public function testGroupOrganizationGetWithWrongParams() {
141 $params = 'groupOrg';
142 $result = civicrm_api('group_organization', 'get', $params);
144 $this->assertEquals($result['is_error'], 1);
145 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
149 * Test civicrm_group_organization_get invalid keys.
151 public function testGroupOrganizationGetWithInvalidKeys() {
154 'version' => $this->_apiversion
,
156 $result = civicrm_api('group_organization', 'get', $params);
158 $this->assertEquals($result['is_error'], 0);
161 ///////////////// civicrm_group_organization_create methods
164 * check with valid params
166 public function testGroupOrganizationCreate() {
168 'organization_id' => $this->_orgID
,
169 'group_id' => $this->_groupID
,
170 'version' => $this->_apiversion
,
172 $result = civicrm_api('group_organization', 'create', $params);
173 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
174 $this->assertAPISuccess($result, "in line " . __LINE__
);
178 * check with empty params array
180 public function testGroupOrganizationCreateWithEmptyParams() {
182 'version' => $this->_apiversion
,
184 $result = civicrm_api('group_organization', 'create', $params);
186 $this->assertEquals($result['is_error'], 1);
187 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
191 * check with invalid params
193 public function testGroupOrganizationCreateParamsNotArray() {
194 $params = 'group_org';
195 $result = civicrm_api('group_organization', 'create', $params);
197 $this->assertEquals($result['is_error'], 1);
198 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
202 * check with invalid params keys
204 public function testGroupOrganizationCreateWithInvalidKeys() {
207 'version' => $this->_apiversion
,
209 $result = civicrm_api('group_organization', 'create', $params);
211 $this->assertEquals($result['is_error'], 1);
212 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
215 ///////////////// civicrm_group_organization_remove methods
218 * Test civicrm_group_organization_remove with params not an array.
220 public function testGroupOrganizationDeleteParamsNotArray() {
222 $result = civicrm_api('group_organization', 'delete', $params);
224 $this->assertEquals($result['is_error'], 1);
225 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
229 * Test civicrm_group_organization_remove with empty params.
231 public function testGroupOrganizationDeleteWithEmptyParams() {
233 'version' => $this->_apiversion
,
235 $result = civicrm_api('group_organization', 'delete', $params);
237 $this->assertEquals($result['is_error'], 1);
238 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
242 * Test civicrm_group_organization_remove with valid params.
244 public function testGroupOrganizationDelete() {
246 'organization_id' => $this->_orgID
,
247 'group_id' => $this->_groupID
,
248 'version' => $this->_apiversion
,
250 $result = civicrm_api('group_organization', 'create', $paramsC);
253 'id' => $result['id'],
254 'version' => $this->_apiversion
,
256 $result = civicrm_api('group_organization', 'delete', $params);
257 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
258 $this->assertAPISuccess($result, "in line " . __LINE__
);
262 * Test civicrm_group_organization_remove with invalid params key.
264 public function testGroupOrganizationDeleteWithInvalidKey() {
265 $paramsDelete = array(
267 'version' => $this->_apiversion
,
269 $result = civicrm_api('group_organization', 'delete', $paramsDelete);
271 $this->assertEquals($result['is_error'], 1);
272 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');