Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-10-18-35-58
[civicrm-core.git] / tests / phpunit / api / v3 / GroupOrganizationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 public $_eNoticeCompliant = True;
39
40 function get_info() {
41 return array(
42 'name' => 'Group Organization',
43 'description' => 'Test all Group Organization API methods.',
44 'group' => 'CiviCRM API Tests',
45 );
46 }
47
48 /**
49 * Sets up the fixture, for example, opens a network connection.
50 * This method is called before a test is executed.
51 *
52 * @access protected
53 */
54 protected function setUp() {
55 $this->_apiversion = 3;
56 parent::setUp();
57 $this->_groupID = $this->groupCreate(NULL);
58
59 $this->_orgID = $this->organizationCreate(NULL);
60 }
61
62 /**
63 * Tears down the fixture, for example, closes a network connection.
64 * This method is called after a test is executed.
65 *
66 * @access protected
67 */
68 protected function tearDown() {
69 // Truncate the tables
70 $this->quickCleanup(
71 array(
72 'civicrm_group',
73 'civicrm_group_organization',
74 'civicrm_contact',
75 'civicrm_uf_group',
76 'civicrm_uf_join',
77 'civicrm_uf_match',
78 )
79 );
80 }
81
82 ///////////////// civicrm_group_organization_get methods
83
84 /**
85 * Test civicrm_group_organization_get with valid params.
86 */
87 public function testGroupOrganizationGet() {
88
89 $params = array(
90 'organization_id' => $this->_orgID,
91 'group_id' => $this->_groupID, );
92 $result = $this->callAPISuccess('group_organization', 'create', $params);
93 $paramsGet = array(
94 'organization_id' => $result['id'],
95 );
96 $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__);
97 }
98
99 /**
100 * Test civicrm_group_organization_get with group_id.
101 */
102 public function testGroupOrganizationGetWithGroupId() {
103
104 $params = array(
105 'organization_id' => $this->_orgID,
106 'group_id' => $this->_groupID, 'sequential' => 1,
107 );
108 $result = $this->callAPISuccess('group_organization', 'create', $params);
109
110 $paramsGet = array('organization_id' => $result['values'][0]['organization_id']);
111
112 $result = $this->callAPISuccess('group_organization', 'get', $params);
113 $this->assertAPISuccess($result);
114 }
115
116 /**
117 * Test civicrm_group_organization_get with empty params.
118 */
119 public function testGroupOrganizationGetWithEmptyParams() {
120 $params = array( );
121 $result = $this->callAPISuccess('group_organization', 'get', $params);
122
123 $this->assertAPISuccess($result);
124 }
125
126 /**
127 * Test civicrm_group_organization_get with wrong params.
128 */
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');
133 }
134
135 /**
136 * Test civicrm_group_organization_get invalid keys.
137 */
138 public function testGroupOrganizationGetWithInvalidKeys() {
139 $params = array(
140 'invalid_key' => 1, );
141 $result = $this->callAPISuccess('group_organization', 'get', $params);
142
143 $this->assertAPISuccess($result);
144 }
145
146 ///////////////// civicrm_group_organization_create methods
147
148 /**
149 * check with valid params
150 */
151 public function testGroupOrganizationCreate() {
152 $params = array(
153 'organization_id' => $this->_orgID,
154 'group_id' => $this->_groupID, );
155 $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__);
156 }
157
158 /**
159 * check with empty params array
160 */
161 public function testGroupOrganizationCreateWithEmptyParams() {
162 $params = array( );
163 $result = $this->callAPIFailure('group_organization', 'create', $params);
164 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
165 }
166
167 /**
168 * check with invalid params
169 */
170 public function testGroupOrganizationCreateParamsNotArray() {
171 $params = 'group_org';
172 $result = $this->callAPIFailure('group_organization', 'create', $params);
173 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
174 }
175
176 /**
177 * check with invalid params keys
178 */
179 public function testGroupOrganizationCreateWithInvalidKeys() {
180 $params = array(
181 'invalid_key' => 1, );
182 $result = $this->callAPIFailure('group_organization', 'create', $params);
183 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id');
184 }
185
186 ///////////////// civicrm_group_organization_remove methods
187
188 /**
189 * Test civicrm_group_organization_remove with params not an array.
190 */
191 public function testGroupOrganizationDeleteParamsNotArray() {
192 $params = 'delete';
193 $result = $this->callAPIFailure('group_organization', 'delete', $params);
194 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
195 }
196
197 /**
198 * Test civicrm_group_organization_remove with empty params.
199 */
200 public function testGroupOrganizationDeleteWithEmptyParams() {
201 $params = array( );
202 $result = $this->callAPIFailure('group_organization', 'delete', $params);
203 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
204 }
205
206 /**
207 * Test civicrm_group_organization_remove with valid params.
208 */
209 public function testGroupOrganizationDelete() {
210 $paramsC = array(
211 'organization_id' => $this->_orgID,
212 'group_id' => $this->_groupID, );
213 $result = $this->callAPISuccess('group_organization', 'create', $paramsC);
214
215 $params = array(
216 'id' => $result['id'],
217 );
218 $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__);
219 }
220
221 /**
222 * Test civicrm_group_organization_remove with invalid params key.
223 */
224 public function testGroupOrganizationDeleteWithInvalidKey() {
225 $paramsDelete = array(
226 'invalid_key' => 1, );
227 $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete);
228 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
229 }
230 }
231