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;
38 public $_eNoticeCompliant = True;
42 'name' => 'Group Organization',
43 'description' => 'Test all Group Organization API methods.',
44 'group' => 'CiviCRM API Tests',
49 * Sets up the fixture, for example, opens a network connection.
50 * This method is called before a test is executed.
54 protected function setUp() {
55 $this->_apiversion
= 3;
57 $this->_groupID
= $this->groupCreate(NULL);
59 $this->_orgID
= $this->organizationCreate(NULL);
63 * Tears down the fixture, for example, closes a network connection.
64 * This method is called after a test is executed.
68 protected function tearDown() {
69 // Truncate the tables
73 'civicrm_group_organization',
82 ///////////////// civicrm_group_organization_get methods
85 * Test civicrm_group_organization_get with valid params.
87 public function testGroupOrganizationGet() {
90 'organization_id' => $this->_orgID
,
91 'group_id' => $this->_groupID
, );
92 $result = $this->callAPISuccess('group_organization', 'create', $params);
94 'organization_id' => $result['id'],
96 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
100 * Test civicrm_group_organization_get with group_id.
102 public function testGroupOrganizationGetWithGroupId() {
105 'organization_id' => $this->_orgID
,
106 'group_id' => $this->_groupID
, 'sequential' => 1,
108 $result = $this->callAPISuccess('group_organization', 'create', $params);
110 $paramsGet = array('organization_id' => $result['values'][0]['organization_id']);
112 $result = $this->callAPISuccess('group_organization', 'get', $params);
113 $this->assertAPISuccess($result);
117 * Test civicrm_group_organization_get with empty params.
119 public function testGroupOrganizationGetWithEmptyParams() {
121 $result = $this->callAPISuccess('group_organization', 'get', $params);
123 $this->assertAPISuccess($result);
127 * Test civicrm_group_organization_get with wrong params.
129 public function testGroupOrganizationGetWithWrongParams() {
130 $params = 'groupOrg';
131 $result = $this->callAPIFailure('group_organization', 'get', $params);
132 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
136 * Test civicrm_group_organization_get invalid keys.
138 public function testGroupOrganizationGetWithInvalidKeys() {
140 'invalid_key' => 1, );
141 $result = $this->callAPISuccess('group_organization', 'get', $params);
143 $this->assertAPISuccess($result);
146 ///////////////// civicrm_group_organization_create methods
149 * check with valid params
151 public function testGroupOrganizationCreate() {
153 'organization_id' => $this->_orgID
,
154 'group_id' => $this->_groupID
, );
155 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
159 * CRM-13841 - Load Group Org before save
161 public function testGroupOrganizationCreateTwice() {
163 'organization_id' => $this->_orgID
,
164 'group_id' => $this->_groupID
, );
165 $result = $this->callAPISuccess('group_organization', 'create', $params);
166 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
167 $this->assertEquals($result['values'], $result2['values']);
170 * check with empty params array
172 public function testGroupOrganizationCreateWithEmptyParams() {
174 $result = $this->callAPIFailure('group_organization', 'create', $params);
175 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
179 * check with invalid params
181 public function testGroupOrganizationCreateParamsNotArray() {
182 $params = 'group_org';
183 $result = $this->callAPIFailure('group_organization', 'create', $params);
184 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
188 * check with invalid params keys
190 public function testGroupOrganizationCreateWithInvalidKeys() {
192 'invalid_key' => 1, );
193 $result = $this->callAPIFailure('group_organization', 'create', $params);
194 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
197 ///////////////// civicrm_group_organization_remove methods
200 * Test civicrm_group_organization_remove with params not an array.
202 public function testGroupOrganizationDeleteParamsNotArray() {
204 $result = $this->callAPIFailure('group_organization', 'delete', $params);
205 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
209 * Test civicrm_group_organization_remove with empty params.
211 public function testGroupOrganizationDeleteWithEmptyParams() {
213 $result = $this->callAPIFailure('group_organization', 'delete', $params);
214 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
218 * Test civicrm_group_organization_remove with valid params.
220 public function testGroupOrganizationDelete() {
222 'organization_id' => $this->_orgID
,
223 'group_id' => $this->_groupID
, );
224 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
227 'id' => $result['id'],
229 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
233 * Test civicrm_group_organization_remove with invalid params key.
235 public function testGroupOrganizationDeleteWithInvalidKey() {
236 $paramsDelete = array(
237 'invalid_key' => 1, );
238 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
239 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');