Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | * | |
6c6e6187 | 34 | * @package CiviCRM |
6a488035 TO |
35 | */ |
36 | class api_v3_GroupOrganizationTest extends CiviUnitTestCase { | |
37 | protected $_apiversion; | |
6a488035 | 38 | |
6a488035 TO |
39 | /** |
40 | * Sets up the fixture, for example, opens a network connection. | |
41 | * This method is called before a test is executed. | |
6a488035 TO |
42 | */ |
43 | protected function setUp() { | |
44 | $this->_apiversion = 3; | |
45 | parent::setUp(); | |
905d864b | 46 | $this->useTransaction(TRUE); |
fadb804f | 47 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
48 | |
49 | $this->_orgID = $this->organizationCreate(NULL); | |
50 | } | |
51 | ||
6a488035 TO |
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, | |
481a74f4 | 61 | 'group_id' => $this->_groupID,); |
2d34d4bb | 62 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
6a488035 TO |
63 | $paramsGet = array( |
64 | 'organization_id' => $result['id'], | |
6a488035 | 65 | ); |
2d34d4bb | 66 | $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); |
6a488035 TO |
67 | } |
68 | ||
69 | /** | |
70 | * Test civicrm_group_organization_get with group_id. | |
71 | */ | |
72 | public function testGroupOrganizationGetWithGroupId() { | |
25396471 | 73 | $createParams = array( |
6a488035 | 74 | 'organization_id' => $this->_orgID, |
25396471 | 75 | 'group_id' => $this->_groupID, |
6a488035 | 76 | ); |
25396471 | 77 | $createResult = $this->callAPISuccess('group_organization', 'create', $createParams); |
6a488035 | 78 | |
25396471 TO |
79 | $getParams = array( |
80 | 'group_id' => $this->_groupID, | |
81 | 'sequential' => 1, | |
82 | ); | |
83 | $getResult = $this->callAPISuccess('group_organization', 'get', $getParams); | |
84 | $this->assertEquals($createResult['values'], $getResult['values'][0]); | |
6a488035 TO |
85 | } |
86 | ||
87 | /** | |
88 | * Test civicrm_group_organization_get with empty params. | |
89 | */ | |
90 | public function testGroupOrganizationGetWithEmptyParams() { | |
6c6e6187 | 91 | $params = array(); |
2d34d4bb | 92 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 93 | |
791c263c | 94 | $this->assertAPISuccess($result); |
6a488035 TO |
95 | } |
96 | ||
97 | /** | |
98 | * Test civicrm_group_organization_get with wrong params. | |
99 | */ | |
100 | public function testGroupOrganizationGetWithWrongParams() { | |
101 | $params = 'groupOrg'; | |
d0e1eff2 | 102 | $result = $this->callAPIFailure('group_organization', 'get', $params); |
6a488035 TO |
103 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
104 | } | |
105 | ||
106 | /** | |
107 | * Test civicrm_group_organization_get invalid keys. | |
108 | */ | |
109 | public function testGroupOrganizationGetWithInvalidKeys() { | |
110 | $params = array( | |
481a74f4 | 111 | 'invalid_key' => 1,); |
2d34d4bb | 112 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 113 | |
791c263c | 114 | $this->assertAPISuccess($result); |
6a488035 TO |
115 | } |
116 | ||
117 | ///////////////// civicrm_group_organization_create methods | |
118 | ||
119 | /** | |
100fef9d | 120 | * Check with valid params |
6a488035 TO |
121 | */ |
122 | public function testGroupOrganizationCreate() { | |
123 | $params = array( | |
124 | 'organization_id' => $this->_orgID, | |
481a74f4 | 125 | 'group_id' => $this->_groupID,); |
2d34d4bb | 126 | $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
127 | } |
128 | ||
c69fdfbb E |
129 | /** |
130 | * CRM-13841 - Load Group Org before save | |
131 | */ | |
132 | public function testGroupOrganizationCreateTwice() { | |
133 | $params = array( | |
134 | 'organization_id' => $this->_orgID, | |
481a74f4 | 135 | 'group_id' => $this->_groupID,); |
c69fdfbb E |
136 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
137 | $result2 = $this->callAPISuccess('group_organization', 'create', $params); | |
138 | $this->assertEquals($result['values'], $result2['values']); | |
139 | } | |
6a488035 | 140 | /** |
100fef9d | 141 | * Check with empty params array |
6a488035 TO |
142 | */ |
143 | public function testGroupOrganizationCreateWithEmptyParams() { | |
6c6e6187 | 144 | $params = array(); |
d0e1eff2 | 145 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
146 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
147 | } | |
148 | ||
149 | /** | |
100fef9d | 150 | * Check with invalid params |
6a488035 TO |
151 | */ |
152 | public function testGroupOrganizationCreateParamsNotArray() { | |
153 | $params = 'group_org'; | |
d0e1eff2 | 154 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
155 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
156 | } | |
157 | ||
158 | /** | |
100fef9d | 159 | * Check with invalid params keys |
6a488035 TO |
160 | */ |
161 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
162 | $params = array( | |
481a74f4 | 163 | 'invalid_key' => 1,); |
d0e1eff2 | 164 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
165 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
166 | } | |
167 | ||
168 | ///////////////// civicrm_group_organization_remove methods | |
169 | ||
170 | /** | |
171 | * Test civicrm_group_organization_remove with params not an array. | |
172 | */ | |
173 | public function testGroupOrganizationDeleteParamsNotArray() { | |
174 | $params = 'delete'; | |
d0e1eff2 | 175 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
176 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
177 | } | |
178 | ||
179 | /** | |
180 | * Test civicrm_group_organization_remove with empty params. | |
181 | */ | |
182 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
6c6e6187 | 183 | $params = array(); |
d0e1eff2 | 184 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
185 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
186 | } | |
187 | ||
188 | /** | |
189 | * Test civicrm_group_organization_remove with valid params. | |
190 | */ | |
191 | public function testGroupOrganizationDelete() { | |
192 | $paramsC = array( | |
193 | 'organization_id' => $this->_orgID, | |
481a74f4 | 194 | 'group_id' => $this->_groupID,); |
2d34d4bb | 195 | $result = $this->callAPISuccess('group_organization', 'create', $paramsC); |
6a488035 TO |
196 | |
197 | $params = array( | |
198 | 'id' => $result['id'], | |
6a488035 | 199 | ); |
2d34d4bb | 200 | $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
201 | } |
202 | ||
203 | /** | |
204 | * Test civicrm_group_organization_remove with invalid params key. | |
205 | */ | |
206 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
207 | $paramsDelete = array( | |
481a74f4 | 208 | 'invalid_key' => 1,); |
d0e1eff2 | 209 | $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); |
6a488035 TO |
210 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
211 | } | |
212 | } |