Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
6a488035 TO |
12 | /** |
13 | * Test class for GroupOrganization API - civicrm_group_organization_* | |
14 | * | |
6c6e6187 | 15 | * @package CiviCRM |
acb109b7 | 16 | * @group headless |
6a488035 TO |
17 | */ |
18 | class api_v3_GroupOrganizationTest extends CiviUnitTestCase { | |
19 | protected $_apiversion; | |
6a488035 | 20 | |
6a488035 TO |
21 | /** |
22 | * Sets up the fixture, for example, opens a network connection. | |
23 | * This method is called before a test is executed. | |
6a488035 TO |
24 | */ |
25 | protected function setUp() { | |
26 | $this->_apiversion = 3; | |
27 | parent::setUp(); | |
905d864b | 28 | $this->useTransaction(TRUE); |
fadb804f | 29 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
30 | |
31 | $this->_orgID = $this->organizationCreate(NULL); | |
32 | } | |
33 | ||
6a488035 TO |
34 | ///////////////// civicrm_group_organization_get methods |
35 | ||
36 | /** | |
37 | * Test civicrm_group_organization_get with valid params. | |
0158c2b6 SL |
38 | * |
39 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
40 | */ |
41 | public function testGroupOrganizationGet() { | |
42 | ||
9099cab3 | 43 | $params = [ |
6a488035 | 44 | 'organization_id' => $this->_orgID, |
92915c55 | 45 | 'group_id' => $this->_groupID, |
9099cab3 | 46 | ]; |
2d34d4bb | 47 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
9099cab3 | 48 | $paramsGet = [ |
6a488035 | 49 | 'organization_id' => $result['id'], |
9099cab3 | 50 | ]; |
2d34d4bb | 51 | $result = $this->callAPIAndDocument('group_organization', 'get', $paramsGet, __FUNCTION__, __FILE__); |
6a488035 TO |
52 | } |
53 | ||
54 | /** | |
55 | * Test civicrm_group_organization_get with group_id. | |
0158c2b6 SL |
56 | * |
57 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
58 | */ |
59 | public function testGroupOrganizationGetWithGroupId() { | |
9099cab3 | 60 | $createParams = [ |
6a488035 | 61 | 'organization_id' => $this->_orgID, |
25396471 | 62 | 'group_id' => $this->_groupID, |
9099cab3 | 63 | ]; |
25396471 | 64 | $createResult = $this->callAPISuccess('group_organization', 'create', $createParams); |
6a488035 | 65 | |
9099cab3 | 66 | $getParams = [ |
25396471 TO |
67 | 'group_id' => $this->_groupID, |
68 | 'sequential' => 1, | |
9099cab3 | 69 | ]; |
25396471 | 70 | $getResult = $this->callAPISuccess('group_organization', 'get', $getParams); |
1237d8d7 | 71 | $this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]); |
6a488035 TO |
72 | } |
73 | ||
74 | /** | |
75 | * Test civicrm_group_organization_get with empty params. | |
0158c2b6 SL |
76 | * |
77 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
78 | */ |
79 | public function testGroupOrganizationGetWithEmptyParams() { | |
9099cab3 | 80 | $params = []; |
2d34d4bb | 81 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 82 | |
791c263c | 83 | $this->assertAPISuccess($result); |
6a488035 TO |
84 | } |
85 | ||
6a488035 TO |
86 | /** |
87 | * Test civicrm_group_organization_get invalid keys. | |
0158c2b6 SL |
88 | * |
89 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
90 | */ |
91 | public function testGroupOrganizationGetWithInvalidKeys() { | |
9099cab3 | 92 | $params = [ |
92915c55 | 93 | 'invalid_key' => 1, |
9099cab3 | 94 | ]; |
2d34d4bb | 95 | $result = $this->callAPISuccess('group_organization', 'get', $params); |
6a488035 | 96 | |
791c263c | 97 | $this->assertAPISuccess($result); |
6a488035 TO |
98 | } |
99 | ||
100 | ///////////////// civicrm_group_organization_create methods | |
101 | ||
102 | /** | |
eceb18cc | 103 | * Check with valid params. |
0158c2b6 SL |
104 | * |
105 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
106 | */ |
107 | public function testGroupOrganizationCreate() { | |
9099cab3 | 108 | $params = [ |
6a488035 | 109 | 'organization_id' => $this->_orgID, |
92915c55 | 110 | 'group_id' => $this->_groupID, |
9099cab3 | 111 | ]; |
2d34d4bb | 112 | $result = $this->callAPIAndDocument('group_organization', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
113 | } |
114 | ||
c69fdfbb E |
115 | /** |
116 | * CRM-13841 - Load Group Org before save | |
0158c2b6 SL |
117 | * |
118 | * @dataProvider versionThreeAndFour | |
c69fdfbb E |
119 | */ |
120 | public function testGroupOrganizationCreateTwice() { | |
9099cab3 | 121 | $params = [ |
92915c55 TO |
122 | 'organization_id' => $this->_orgID, |
123 | 'group_id' => $this->_groupID, | |
9099cab3 | 124 | ]; |
c69fdfbb E |
125 | $result = $this->callAPISuccess('group_organization', 'create', $params); |
126 | $result2 = $this->callAPISuccess('group_organization', 'create', $params); | |
127 | $this->assertEquals($result['values'], $result2['values']); | |
128 | } | |
92915c55 | 129 | |
6a488035 | 130 | /** |
eceb18cc | 131 | * Check with empty params array. |
0158c2b6 SL |
132 | * |
133 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
134 | */ |
135 | public function testGroupOrganizationCreateWithEmptyParams() { | |
9099cab3 | 136 | $params = []; |
d0e1eff2 | 137 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
138 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
139 | } | |
140 | ||
6a488035 | 141 | /** |
eceb18cc | 142 | * Check with invalid params keys. |
0158c2b6 SL |
143 | * |
144 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
145 | */ |
146 | public function testGroupOrganizationCreateWithInvalidKeys() { | |
9099cab3 | 147 | $params = [ |
92915c55 | 148 | 'invalid_key' => 1, |
9099cab3 | 149 | ]; |
d0e1eff2 | 150 | $result = $this->callAPIFailure('group_organization', 'create', $params); |
6a488035 TO |
151 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); |
152 | } | |
153 | ||
154 | ///////////////// civicrm_group_organization_remove methods | |
155 | ||
6a488035 TO |
156 | /** |
157 | * Test civicrm_group_organization_remove with empty params. | |
0158c2b6 SL |
158 | * |
159 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
160 | */ |
161 | public function testGroupOrganizationDeleteWithEmptyParams() { | |
9099cab3 | 162 | $params = []; |
d0e1eff2 | 163 | $result = $this->callAPIFailure('group_organization', 'delete', $params); |
6a488035 TO |
164 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
165 | } | |
166 | ||
167 | /** | |
d177a2a6 | 168 | * Test civicrm_group_organization_remove with valid params. |
0158c2b6 SL |
169 | * |
170 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
171 | */ |
172 | public function testGroupOrganizationDelete() { | |
9099cab3 | 173 | $paramsC = [ |
6a488035 | 174 | 'organization_id' => $this->_orgID, |
92915c55 | 175 | 'group_id' => $this->_groupID, |
9099cab3 | 176 | ]; |
2d34d4bb | 177 | $result = $this->callAPISuccess('group_organization', 'create', $paramsC); |
6a488035 | 178 | |
9099cab3 | 179 | $params = [ |
6a488035 | 180 | 'id' => $result['id'], |
9099cab3 | 181 | ]; |
2d34d4bb | 182 | $result = $this->callAPIAndDocument('group_organization', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
183 | } |
184 | ||
185 | /** | |
d177a2a6 | 186 | * Test civicrm_group_organization_remove with invalid params key. |
0158c2b6 SL |
187 | * |
188 | * @dataProvider versionThreeAndFour | |
6a488035 TO |
189 | */ |
190 | public function testGroupOrganizationDeleteWithInvalidKey() { | |
9099cab3 | 191 | $paramsDelete = [ |
92915c55 | 192 | 'invalid_key' => 1, |
9099cab3 | 193 | ]; |
d0e1eff2 | 194 | $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); |
6a488035 TO |
195 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); |
196 | } | |
96025800 | 197 | |
6a488035 | 198 | } |