3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * Test class for GroupOrganization API - civicrm_group_organization_*
33 class api_v3_GroupOrganizationTest
extends CiviUnitTestCase
{
34 protected $_apiversion;
37 * Sets up the fixture, for example, opens a network connection.
38 * This method is called before a test is executed.
40 protected function setUp() {
41 $this->_apiversion
= 3;
43 $this->useTransaction(TRUE);
44 $this->_groupID
= $this->groupCreate();
46 $this->_orgID
= $this->organizationCreate(NULL);
49 ///////////////// civicrm_group_organization_get methods
52 * Test civicrm_group_organization_get with valid params.
54 public function testGroupOrganizationGet() {
57 'organization_id' => $this->_orgID
,
58 'group_id' => $this->_groupID
,
60 $result = $this->callAPISuccess('group_organization', 'create', $params);
62 'organization_id' => $result['id'],
64 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__
, __FILE__
);
68 * Test civicrm_group_organization_get with group_id.
70 public function testGroupOrganizationGetWithGroupId() {
71 $createParams = array(
72 'organization_id' => $this->_orgID
,
73 'group_id' => $this->_groupID
,
75 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
78 'group_id' => $this->_groupID
,
81 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
82 $this->assertEquals($createResult['values'], $getResult['values'][0]);
86 * Test civicrm_group_organization_get with empty params.
88 public function testGroupOrganizationGetWithEmptyParams() {
90 $result = $this->callAPISuccess('group_organization', 'get', $params);
92 $this->assertAPISuccess($result);
96 * Test civicrm_group_organization_get with wrong params.
98 public function testGroupOrganizationGetWithWrongParams() {
100 $result = $this->callAPIFailure('group_organization', 'get', $params);
101 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
105 * Test civicrm_group_organization_get invalid keys.
107 public function testGroupOrganizationGetWithInvalidKeys() {
111 $result = $this->callAPISuccess('group_organization', 'get', $params);
113 $this->assertAPISuccess($result);
116 ///////////////// civicrm_group_organization_create methods
119 * Check with valid params.
121 public function testGroupOrganizationCreate() {
123 'organization_id' => $this->_orgID
,
124 'group_id' => $this->_groupID
,
126 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__
, __FILE__
);
130 * CRM-13841 - Load Group Org before save
132 public function testGroupOrganizationCreateTwice() {
134 'organization_id' => $this->_orgID
,
135 'group_id' => $this->_groupID
,
137 $result = $this->callAPISuccess('group_organization', 'create', $params);
138 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
139 $this->assertEquals($result['values'], $result2['values']);
143 * Check with empty params array.
145 public function testGroupOrganizationCreateWithEmptyParams() {
147 $result = $this->callAPIFailure('group_organization', 'create', $params);
148 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
152 * Check with invalid params.
154 public function testGroupOrganizationCreateParamsNotArray() {
155 $params = 'group_org';
156 $result = $this->callAPIFailure('group_organization', 'create', $params);
157 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
161 * Check with invalid params keys.
163 public function testGroupOrganizationCreateWithInvalidKeys() {
167 $result = $this->callAPIFailure('group_organization', 'create', $params);
168 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
171 ///////////////// civicrm_group_organization_remove methods
174 * Test civicrm_group_organization_remove with params not an array.
176 public function testGroupOrganizationDeleteParamsNotArray() {
178 $result = $this->callAPIFailure('group_organization', 'delete', $params);
179 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
183 * Test civicrm_group_organization_remove with empty params.
185 public function testGroupOrganizationDeleteWithEmptyParams() {
187 $result = $this->callAPIFailure('group_organization', 'delete', $params);
188 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
192 * Test civicrm_group_organization_remove with valid params.
194 public function testGroupOrganizationDelete() {
196 'organization_id' => $this->_orgID
,
197 'group_id' => $this->_groupID
,
199 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
202 'id' => $result['id'],
204 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__
, __FILE__
);
208 * Test civicrm_group_organization_remove with invalid params key.
210 public function testGroupOrganizationDeleteWithInvalidKey() {
211 $paramsDelete = array(
214 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
215 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');