commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / api / v3 / GroupOrganizationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31 /**
32 * Test class for GroupOrganization API - civicrm_group_organization_*
33 *
34 * @package CiviCRM
35 */
36 class api_v3_GroupOrganizationTest extends CiviUnitTestCase {
37 protected $_apiversion;
38
39 /**
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
42 */
43 protected function setUp() {
44 $this->_apiversion = 3;
45 parent::setUp();
46 $this->useTransaction(TRUE);
47 $this->_groupID = $this->groupCreate();
48
49 $this->_orgID = $this->organizationCreate(NULL);
50 }
51
52 ///////////////// civicrm_group_organization_get methods
53
54 /**
55 * Test civicrm_group_organization_get with valid params.
56 */
57 public function testGroupOrganizationGet() {
58
59 $params = array(
60 'organization_id' => $this->_orgID,
61 'group_id' => $this->_groupID,
62 );
63 $result = $this->callAPISuccess('group_organization', 'create', $params);
64 $paramsGet = array(
65 'organization_id' => $result['id'],
66 );
67 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__);
68 }
69
70 /**
71 * Test civicrm_group_organization_get with group_id.
72 */
73 public function testGroupOrganizationGetWithGroupId() {
74 $createParams = array(
75 'organization_id' => $this->_orgID,
76 'group_id' => $this->_groupID,
77 );
78 $createResult = $this->callAPISuccess('group_organization', 'create', $createParams);
79
80 $getParams = array(
81 'group_id' => $this->_groupID,
82 'sequential' => 1,
83 );
84 $getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
85 $this->assertEquals($createResult['values'], $getResult['values'][0]);
86 }
87
88 /**
89 * Test civicrm_group_organization_get with empty params.
90 */
91 public function testGroupOrganizationGetWithEmptyParams() {
92 $params = array();
93 $result = $this->callAPISuccess('group_organization', 'get', $params);
94
95 $this->assertAPISuccess($result);
96 }
97
98 /**
99 * Test civicrm_group_organization_get with wrong params.
100 */
101 public function testGroupOrganizationGetWithWrongParams() {
102 $params = 'groupOrg';
103 $result = $this->callAPIFailure('group_organization', 'get', $params);
104 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
105 }
106
107 /**
108 * Test civicrm_group_organization_get invalid keys.
109 */
110 public function testGroupOrganizationGetWithInvalidKeys() {
111 $params = array(
112 'invalid_key' => 1,
113 );
114 $result = $this->callAPISuccess('group_organization', 'get', $params);
115
116 $this->assertAPISuccess($result);
117 }
118
119 ///////////////// civicrm_group_organization_create methods
120
121 /**
122 * Check with valid params.
123 */
124 public function testGroupOrganizationCreate() {
125 $params = array(
126 'organization_id' => $this->_orgID,
127 'group_id' => $this->_groupID,
128 );
129 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__);
130 }
131
132 /**
133 * CRM-13841 - Load Group Org before save
134 */
135 public function testGroupOrganizationCreateTwice() {
136 $params = array(
137 'organization_id' => $this->_orgID,
138 'group_id' => $this->_groupID,
139 );
140 $result = $this->callAPISuccess('group_organization', 'create', $params);
141 $result2 = $this->callAPISuccess('group_organization', 'create', $params);
142 $this->assertEquals($result['values'], $result2['values']);
143 }
144
145 /**
146 * Check with empty params array.
147 */
148 public function testGroupOrganizationCreateWithEmptyParams() {
149 $params = array();
150 $result = $this->callAPIFailure('group_organization', 'create', $params);
151 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
152 }
153
154 /**
155 * Check with invalid params.
156 */
157 public function testGroupOrganizationCreateParamsNotArray() {
158 $params = 'group_org';
159 $result = $this->callAPIFailure('group_organization', 'create', $params);
160 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
161 }
162
163 /**
164 * Check with invalid params keys.
165 */
166 public function testGroupOrganizationCreateWithInvalidKeys() {
167 $params = array(
168 'invalid_key' => 1,
169 );
170 $result = $this->callAPIFailure('group_organization', 'create', $params);
171 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
172 }
173
174 ///////////////// civicrm_group_organization_remove methods
175
176 /**
177 * Test civicrm_group_organization_remove with params not an array.
178 */
179 public function testGroupOrganizationDeleteParamsNotArray() {
180 $params = 'delete';
181 $result = $this->callAPIFailure('group_organization', 'delete', $params);
182 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
183 }
184
185 /**
186 * Test civicrm_group_organization_remove with empty params.
187 */
188 public function testGroupOrganizationDeleteWithEmptyParams() {
189 $params = array();
190 $result = $this->callAPIFailure('group_organization', 'delete', $params);
191 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
192 }
193
194 /**
195 * Test civicrm_group_organization_remove with valid params.
196 */
197 public function testGroupOrganizationDelete() {
198 $paramsC = array(
199 'organization_id' => $this->_orgID,
200 'group_id' => $this->_groupID,
201 );
202 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
203
204 $params = array(
205 'id' => $result['id'],
206 );
207 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__);
208 }
209
210 /**
211 * Test civicrm_group_organization_remove with invalid params key.
212 */
213 public function testGroupOrganizationDeleteWithInvalidKey() {
214 $paramsDelete = array(
215 'invalid_key' => 1,
216 );
217 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
218 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
219 }
220
221 }