Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
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 | * Test class for Batch API - civicrm_participant_* | |
32 | * | |
92915c55 | 33 | * @package CiviCRM_APIv3 |
6a488035 TO |
34 | */ |
35 | require_once 'CRM/Utils/DeprecatedUtils.php'; | |
36 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4cbe18b8 EM |
37 | |
38 | /** | |
39 | * Class api_v3_ParticipantTest | |
40 | */ | |
6a488035 TO |
41 | class api_v3_ParticipantTest extends CiviUnitTestCase { |
42 | ||
43 | protected $_apiversion; | |
44 | protected $_entity; | |
45 | protected $_contactID; | |
46 | protected $_contactID2; | |
47 | protected $_createdParticipants; | |
48 | protected $_participantID; | |
49 | protected $_eventID; | |
50 | protected $_individualId; | |
51 | protected $_params; | |
6a488035 | 52 | |
00be9182 | 53 | public function setUp() { |
6a488035 TO |
54 | $this->_apiversion = 3; |
55 | parent::setUp(); | |
92915c55 TO |
56 | $this->_entity = 'participant'; |
57 | $event = $this->eventCreate(NULL); | |
6a488035 TO |
58 | $this->_eventID = $event['id']; |
59 | ||
e4d5f1e2 | 60 | $this->_contactID = $this->individualCreate(); |
6a488035 TO |
61 | |
62 | $this->_createdParticipants = array(); | |
e4d5f1e2 | 63 | $this->_individualId = $this->individualCreate(); |
6a488035 | 64 | |
92915c55 TO |
65 | $this->_participantID = $this->participantCreate(array( |
66 | 'contact_id' => $this->_contactID, | |
408b79bf | 67 | 'event_id' => $this->_eventID, |
92915c55 | 68 | )); |
e4d5f1e2 | 69 | $this->_contactID2 = $this->individualCreate(); |
92915c55 TO |
70 | $this->_participantID2 = $this->participantCreate(array( |
71 | 'contact_id' => $this->_contactID2, | |
408b79bf | 72 | 'event_id' => $this->_eventID, |
92915c55 TO |
73 | )); |
74 | $this->_participantID3 = $this->participantCreate(array( | |
75 | 'contact_id' => $this->_contactID2, | |
408b79bf | 76 | 'event_id' => $this->_eventID, |
92915c55 | 77 | )); |
6a488035 TO |
78 | $this->_params = array( |
79 | 'contact_id' => $this->_contactID, | |
80 | 'event_id' => $this->_eventID, | |
81 | 'status_id' => 1, | |
82 | 'role_id' => 1, | |
83 | // to ensure it matches later on | |
84 | 'register_date' => '2007-07-21 00:00:00', | |
85 | 'source' => 'Online Event Registration: API Testing', | |
6a488035 TO |
86 | ); |
87 | } | |
88 | ||
00be9182 | 89 | public function tearDown() { |
6a488035 TO |
90 | $this->eventDelete($this->_eventID); |
91 | $tablesToTruncate = array( | |
92915c55 TO |
92 | 'civicrm_custom_group', |
93 | 'civicrm_custom_field', | |
94 | 'civicrm_contact', | |
95 | 'civicrm_participant', | |
6a488035 TO |
96 | ); |
97 | // true tells quickCleanup to drop any tables that might have been created in the test | |
98 | $this->quickCleanup($tablesToTruncate, TRUE); | |
99 | } | |
100 | ||
101 | /** | |
100fef9d | 102 | * Check with complete array + custom field |
6a488035 TO |
103 | * Note that the test is written on purpose without any |
104 | * variables specific to participant so it can be replicated into other entities | |
105 | * and / or moved to the automated test suite | |
106 | */ | |
00be9182 | 107 | public function testCreateWithCustom() { |
6a488035 TO |
108 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
109 | ||
110 | $params = $this->_params; | |
111 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
112 | ||
afd404ea | 113 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
114 | ||
6a488035 | 115 | $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); |
6a488035 | 116 | |
afd404ea | 117 | $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'])); |
6a488035 TO |
118 | $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
119 | ||
120 | $this->customFieldDelete($ids['custom_field_id']); | |
121 | $this->customGroupDelete($ids['custom_group_id']); | |
122 | } | |
123 | ||
124 | ||
125 | ///////////////// civicrm_participant_get methods | |
126 | ||
127 | /** | |
100fef9d | 128 | * Check with wrong params type |
6a488035 | 129 | */ |
00be9182 | 130 | public function testGetWrongParamsType() { |
6a488035 | 131 | $params = 'a string'; |
d0e1eff2 | 132 | $result = $this->callAPIFailure('participant', 'get', $params); |
6a488035 TO |
133 | } |
134 | ||
135 | /** | |
136 | * Test civicrm_participant_get with empty params | |
137 | */ | |
00be9182 | 138 | public function testGetEmptyParams() { |
d0e1eff2 | 139 | $this->callAPISuccess('participant', 'get', array()); |
6a488035 TO |
140 | } |
141 | ||
142 | /** | |
100fef9d | 143 | * Check with participant_id |
6a488035 | 144 | */ |
00be9182 | 145 | public function testGetParticipantIdOnly() { |
6a488035 TO |
146 | $params = array( |
147 | 'participant_id' => $this->_participantID, | |
6a488035 TO |
148 | 'return' => array( |
149 | 'participant_id', | |
150 | 'event_id', | |
151 | 'participant_register_date', | |
152 | 'participant_source', | |
21dfd5f5 | 153 | ), |
6a488035 | 154 | ); |
afd404ea | 155 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
156 | $this->assertAPISuccess($result, " in line " . __LINE__); |
157 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID, "in line " . __LINE__); | |
158 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00', "in line " . __LINE__); | |
159 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon', "in line " . __LINE__); | |
6c6e6187 | 160 | $params = array( |
6a488035 | 161 | 'id' => $this->_participantID, |
6a488035 TO |
162 | 'return' => 'id,participant_register_date,event_id', |
163 | ||
164 | ); | |
afd404ea | 165 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
166 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
167 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
168 | ||
169 | } | |
170 | ||
171 | /** | |
100fef9d | 172 | * Check with params id |
6a488035 | 173 | */ |
00be9182 | 174 | public function testGetParamsAsIdOnly() { |
6a488035 TO |
175 | $params = array( |
176 | 'id' => $this->_participantID, | |
6a488035 | 177 | ); |
afd404ea | 178 | $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
179 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
180 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
181 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
182 | $this->assertEquals($result['id'], $result['values'][$this->_participantID]['id']); | |
183 | } | |
184 | ||
185 | /** | |
100fef9d | 186 | * Check with params id |
6a488035 | 187 | */ |
00be9182 | 188 | public function testGetNestedEventGet() { |
6a488035 TO |
189 | //create a second event & add participant to it. |
190 | $event = $this->eventCreate(NULL); | |
92915c55 TO |
191 | $this->callAPISuccess('participant', 'create', array( |
192 | 'event_id' => $event['id'], | |
408b79bf | 193 | 'contact_id' => $this->_contactID, |
92915c55 | 194 | )); |
6a488035 | 195 | |
6a488035 | 196 | $description = "use nested get to get an event"; |
92915c55 TO |
197 | $subfile = "NestedEventGet"; |
198 | $params = array( | |
6a488035 | 199 | 'id' => $this->_participantID, |
6a488035 TO |
200 | 'api.event.get' => 1, |
201 | ); | |
afd404ea | 202 | $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
203 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
204 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
205 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
206 | $this->assertEquals($this->_eventID, $result['values'][$this->_participantID]['api.event.get']['id']); | |
207 | } | |
c490a46a CW |
208 | |
209 | /** | |
210 | * Check Participant Get respects return properties | |
211 | */ | |
00be9182 | 212 | public function testGetWithReturnProperties() { |
6a488035 | 213 | $params = array( |
6c6e6187 | 214 | 'contact_id' => $this->_contactID, |
92915c55 | 215 | 'return.status_id' => 1, |
6a488035 | 216 | 'return.participant_status_id' => 1, |
21dfd5f5 | 217 | 'options' => array('limit' => 1), |
6a488035 | 218 | ); |
afd404ea | 219 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
220 | $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]); |
221 | } | |
222 | ||
223 | /** | |
100fef9d | 224 | * Check with contact_id |
6a488035 | 225 | */ |
00be9182 | 226 | public function testGetContactIdOnly() { |
6a488035 | 227 | $params = array( |
92915c55 TO |
228 | 'contact_id' => $this->_contactID, |
229 | ); | |
afd404ea | 230 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
231 | |
232 | $this->assertEquals($this->_participantID, $participant['id'], | |
233 | "In line " . __LINE__ | |
234 | ); | |
235 | $this->assertEquals($this->_eventID, $participant['values'][$participant['id']]['event_id'], | |
236 | "In line " . __LINE__ | |
237 | ); | |
238 | $this->assertEquals('2007-02-19 00:00:00', $participant['values'][$participant['id']]['participant_register_date'], | |
239 | "In line " . __LINE__ | |
240 | ); | |
241 | $this->assertEquals('Wimbeldon', $participant['values'][$participant['id']]['participant_source'], | |
242 | "In line " . __LINE__ | |
243 | ); | |
244 | $this->assertEquals($participant['id'], $participant['values'][$participant['id']]['id'], | |
245 | "In line " . __LINE__ | |
246 | ); | |
247 | } | |
248 | ||
249 | /** | |
100fef9d | 250 | * Check with event_id |
6a488035 TO |
251 | * fetch first record |
252 | */ | |
00be9182 | 253 | public function testGetMultiMatchReturnFirst() { |
6a488035 TO |
254 | $params = array( |
255 | 'event_id' => $this->_eventID, | |
92915c55 TO |
256 | 'rowCount' => 1, |
257 | ); | |
6a488035 | 258 | |
afd404ea | 259 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
260 | $this->assertNotNull($participant['id']); |
261 | } | |
262 | ||
263 | /** | |
100fef9d | 264 | * Check with event_id |
6a488035 TO |
265 | * in v3 this should return all participants |
266 | */ | |
00be9182 | 267 | public function testGetMultiMatchNoReturnFirst() { |
6a488035 TO |
268 | $params = array( |
269 | 'event_id' => $this->_eventID, | |
6a488035 | 270 | ); |
afd404ea | 271 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
272 | $this->assertNotNull($participant['count'], 3); |
273 | } | |
274 | ||
275 | ///////////////// civicrm_participant_get methods | |
276 | ||
6a488035 TO |
277 | /** |
278 | * Test civicrm_participant_get with empty params | |
279 | * In this case all the participant records are returned. | |
280 | */ | |
00be9182 | 281 | public function testSearchEmptyParams() { |
afd404ea | 282 | $result = $this->callAPISuccess('participant', 'get', array()); |
6a488035 TO |
283 | // expecting 3 participant records |
284 | $this->assertEquals($result['count'], 3); | |
285 | } | |
286 | ||
287 | /** | |
100fef9d | 288 | * Check with participant_id |
6a488035 | 289 | */ |
00be9182 | 290 | public function testSearchParticipantIdOnly() { |
6a488035 TO |
291 | $params = array( |
292 | 'participant_id' => $this->_participantID, | |
6a488035 | 293 | ); |
afd404ea | 294 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
295 | $this->assertEquals($participant['values'][$this->_participantID]['event_id'], $this->_eventID); |
296 | $this->assertEquals($participant['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
297 | $this->assertEquals($participant['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
298 | } | |
299 | ||
300 | /** | |
100fef9d | 301 | * Check with contact_id |
6a488035 | 302 | */ |
00be9182 | 303 | public function testSearchContactIdOnly() { |
6a488035 TO |
304 | // Should get 2 participant records for this contact. |
305 | $params = array( | |
306 | 'contact_id' => $this->_contactID2, | |
6a488035 | 307 | ); |
afd404ea | 308 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
309 | |
310 | $this->assertEquals($participant['count'], 2); | |
311 | } | |
312 | ||
313 | /** | |
100fef9d | 314 | * Check with event_id |
6a488035 | 315 | */ |
00be9182 | 316 | public function testSearchByEvent() { |
6a488035 TO |
317 | // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned. |
318 | $params = array( | |
319 | 'event_id' => $this->_eventID, | |
320 | 'return.last_name' => 1, | |
321 | 'return.event_title' => 1, | |
6a488035 | 322 | ); |
afd404ea | 323 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
324 | if ($participant['count'] < 3) { |
325 | $this->fail("Event search returned less than expected miniumum of 3 records."); | |
326 | } | |
327 | ||
328 | $this->assertEquals($participant['values'][$this->_participantID]['last_name'], 'Anderson'); | |
329 | $this->assertEquals($participant['values'][$this->_participantID]['event_title'], 'Annual CiviCRM meet'); | |
330 | } | |
331 | ||
332 | /** | |
100fef9d | 333 | * Check with event_id |
6a488035 TO |
334 | * fetch with limit |
335 | */ | |
00be9182 | 336 | public function testSearchByEventWithLimit() { |
6a488035 TO |
337 | // Should 2 participant records since we're passing rowCount = 2. |
338 | $params = array( | |
339 | 'event_id' => $this->_eventID, | |
340 | 'rowCount' => 2, | |
6a488035 | 341 | ); |
afd404ea | 342 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
343 | |
344 | $this->assertEquals($participant['count'], 2, 'in line ' . __LINE__); | |
345 | } | |
346 | ||
347 | ///////////////// civicrm_participant_create methods | |
348 | ||
6a488035 TO |
349 | /** |
350 | * Test civicrm_participant_create with empty params | |
351 | */ | |
00be9182 | 352 | public function testCreateEmptyParams() { |
6a488035 | 353 | $params = array(); |
d0e1eff2 | 354 | $result = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
355 | } |
356 | ||
357 | /** | |
100fef9d | 358 | * Check with event_id |
6a488035 | 359 | */ |
00be9182 | 360 | public function testCreateMissingContactID() { |
6a488035 TO |
361 | $params = array( |
362 | 'event_id' => $this->_eventID, | |
6a488035 | 363 | ); |
afd404ea | 364 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
365 | } |
366 | ||
367 | /** | |
100fef9d | 368 | * Check with contact_id |
6a488035 TO |
369 | * without event_id |
370 | */ | |
00be9182 | 371 | public function testCreateMissingEventID() { |
6a488035 TO |
372 | $params = array( |
373 | 'contact_id' => $this->_contactID, | |
6a488035 | 374 | ); |
afd404ea | 375 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
376 | } |
377 | ||
378 | /** | |
100fef9d | 379 | * Check with contact_id & event_id |
6a488035 | 380 | */ |
00be9182 | 381 | public function testCreateEventIdOnly() { |
6a488035 TO |
382 | $params = array( |
383 | 'contact_id' => $this->_contactID, | |
384 | 'event_id' => $this->_eventID, | |
6a488035 | 385 | ); |
afd404ea | 386 | $participant = $this->callAPISuccess('participant', 'create', $params); |
387 | $this->getAndCheck($params, $participant['id'], 'participant'); | |
6a488035 TO |
388 | } |
389 | ||
390 | /** | |
100fef9d | 391 | * Check with complete array |
6a488035 | 392 | */ |
00be9182 | 393 | public function testCreateAllParams() { |
6a488035 TO |
394 | $params = $this->_params; |
395 | ||
afd404ea | 396 | $participant = $this->callAPISuccess('participant', 'create', $params); |
6a488035 | 397 | $this->_participantID = $participant['id']; |
afd404ea | 398 | // assertDBState compares expected values in $match to actual values in the DB |
399 | $this->assertDBState('CRM_Event_DAO_Participant', $participant['id'], $params); | |
6a488035 | 400 | } |
c490a46a CW |
401 | |
402 | /** | |
403 | * Test to check if receive date is being changed per CRM-9763 | |
404 | */ | |
00be9182 | 405 | public function testCreateUpdateReceiveDate() { |
afd404ea | 406 | $participant = $this->callAPISuccess('participant', 'create', $this->_params); |
6a488035 | 407 | $update = array( |
92915c55 | 408 | 'id' => $participant['id'], |
6a488035 TO |
409 | 'status_id' => 2, |
410 | ); | |
afd404ea | 411 | $this->callAPISuccess('participant', 'create', $update); |
6a488035 TO |
412 | $this->getAndCheck(array_merge($this->_params, $update), $participant['id'], 'participant'); |
413 | } | |
c490a46a CW |
414 | |
415 | /** | |
416 | * Test to check if participant fee level is being changed per CRM-9781 | |
417 | */ | |
00be9182 | 418 | public function testCreateUpdateParticipantFeeLevel() { |
6a488035 | 419 | $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR); |
afd404ea | 420 | $participant = $this->callAPISuccess('participant', 'create', $myParams); |
6a488035 | 421 | $update = array( |
6ead217b | 422 | 'id' => $participant['id'], |
6a488035 TO |
423 | 'status_id' => 2, |
424 | ); | |
6ead217b E |
425 | $update = $this->callAPISuccess('participant', 'create', $update); |
426 | ||
427 | $this->assertEquals($participant['values'][$participant['id']]['fee_level'], | |
428 | $update['values'][$participant['id']]['fee_level'] | |
6a488035 TO |
429 | ); |
430 | ||
afd404ea | 431 | $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); |
6a488035 | 432 | } |
3233fd0f JV |
433 | |
434 | /** | |
c490a46a CW |
435 | * Test the line items for participant fee with multiple price field values. |
436 | */ | |
00be9182 | 437 | public function testCreateParticipantLineItems() { |
3233fd0f JV |
438 | // Create a price set for this event. |
439 | ||
440 | $priceset = $this->callAPISuccess('PriceSet', 'create', array( | |
441 | 'name' => 'my_price_set', | |
442 | 'title' => 'My Price Set', | |
443 | 'is_active' => 1, | |
444 | 'extends' => 1, | |
445 | 'financial_type_id' => 4, | |
446 | // 'entity' => array('civicrm_event' => array($this->_eventID)), | |
447 | )); | |
448 | ||
449 | // Add the price set to the event with another API call. | |
450 | // I tried to do this at once, but it did not work. | |
451 | ||
452 | $priceset = $this->callAPISuccess('PriceSet', 'create', array( | |
453 | 'entity_table' => 'civicrm_event', | |
454 | 'entity_id' => $this->_eventID, | |
455 | 'id' => $priceset['id'], | |
456 | )); | |
457 | ||
458 | $pricefield = $this->callAPISuccess('PriceField', 'create', array( | |
459 | 'price_set_id' => $priceset['id'], | |
460 | 'name' => 'mypricefield', | |
461 | 'label' => 'My Price Field', | |
462 | 'html_type' => 'Text', | |
463 | 'is_enter_qty' => 1, | |
464 | 'is_display_amounts' => 1, | |
465 | 'is_active' => 1, | |
466 | )); | |
467 | ||
468 | $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', array( | |
469 | 'price_field_id' => $pricefield['id'], | |
470 | 'name' => 'pricefieldvalue1', | |
471 | 'label' => 'pricefieldvalue1', | |
472 | 'amount' => 20, | |
473 | 'is_active' => 1, | |
474 | 'financial_type_id' => 4, | |
475 | )); | |
476 | ||
477 | $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', array( | |
478 | 'price_field_id' => $pricefield['id'], | |
479 | 'name' => 'pricefieldvalue2', | |
480 | 'label' => 'pricefieldvalue2', | |
481 | 'amount' => 5, | |
482 | 'is_active' => 1, | |
483 | 'financial_type_id' => 4, | |
484 | )); | |
485 | ||
486 | // pay 2 times price field value 1, and 2 times price field value 2. | |
487 | $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR); | |
488 | $participant = $this->callAPISuccess('participant', 'create', $myParams); | |
489 | ||
490 | // expect 2 line items. | |
491 | $lineItems = $this->callAPISuccess('LineItem', 'get', array( | |
492 | 'entity_id' => $participant['id'], | |
493 | 'entity_table' => 'civicrm_participant', | |
494 | )); | |
495 | ||
496 | $this->assertEquals(2, $lineItems['count']); | |
497 | ||
498 | // Check quantity, label and unit price of lines. | |
31037a42 | 499 | // TODO: These assertions depend on the order of the line items, which is |
3233fd0f | 500 | // technically incorrect. |
d4df7755 JV |
501 | |
502 | $lineItem = array_pop($lineItems['values']); | |
503 | $this->assertEquals(2, $lineItem['qty']); | |
504 | $this->assertEquals(5, $lineItem['unit_price']); | |
505 | $this->assertEquals('pricefieldvalue2', $lineItem['label']); | |
506 | ||
507 | $lineItem = array_pop($lineItems['values']); | |
508 | $this->assertEquals(2, $lineItem['qty']); | |
509 | $this->assertEquals(20, $lineItem['unit_price']); | |
510 | $this->assertEquals('pricefieldvalue1', $lineItem['label']); | |
3233fd0f JV |
511 | |
512 | // Cleanup | |
513 | $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); | |
514 | ||
515 | // TODO: I think the price set should be removed, but I don't know how | |
516 | // to decouple it properly from the event. For the moment, I'll just comment | |
517 | // out the lines below. | |
518 | ||
519 | /* | |
520 | $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv1['id'])); | |
521 | $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv2['id'])); | |
522 | $this->callAPISuccess('PriceField', 'delete', array('id' => $pricefield['id'])); | |
523 | $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceset['id'])); | |
524 | */ | |
525 | } | |
526 | ||
afd404ea | 527 | /** |
100fef9d | 528 | * Check with complete array |
afd404ea | 529 | */ |
00be9182 | 530 | public function testUpdate() { |
6ead217b E |
531 | $participantId = $this->participantCreate(array( |
532 | 'contactID' => $this->_individualId, | |
21dfd5f5 | 533 | 'eventID' => $this->_eventID, |
6ead217b | 534 | )); |
afd404ea | 535 | $params = array( |
536 | 'id' => $participantId, | |
537 | 'contact_id' => $this->_individualId, | |
538 | 'event_id' => $this->_eventID, | |
539 | 'status_id' => 3, | |
540 | 'role_id' => 3, | |
541 | 'register_date' => '2006-01-21', | |
542 | 'source' => 'US Open', | |
afd404ea | 543 | ); |
544 | $participant = $this->callAPISuccess('participant', 'create', $params); | |
545 | $this->getAndCheck($params, $participant['id'], 'participant'); | |
546 | $result = $this->participantDelete($params['id']); | |
547 | } | |
548 | ||
549 | /** | |
550 | * Test to check if participant fee level is being changed per CRM-9781 | |
551 | * Try again without a custom separater to check that one isn't added | |
552 | * (get & check won't accept an array) | |
553 | */ | |
00be9182 | 554 | public function testUpdateCreateParticipantFeeLevelNoSeparator() { |
6a488035 TO |
555 | |
556 | $myParams = $this->_params + array('participant_fee_level' => "fee"); | |
afd404ea | 557 | $participant = $this->callAPISuccess('participant', 'create', $myParams); |
6a488035 TO |
558 | $this->assertAPISuccess($participant); |
559 | $update = array( | |
92915c55 | 560 | 'id' => $participant['id'], |
6a488035 TO |
561 | 'status_id' => 2, |
562 | ); | |
afd404ea | 563 | $this->callAPISuccess('participant', 'create', $update); |
6a488035 TO |
564 | $this->assertEquals($participant['values'][$participant['id']]['fee_level'], |
565 | $myParams['participant_fee_level'] | |
566 | ); | |
567 | $this->getAndCheck($update, $participant['id'], 'participant'); | |
568 | } | |
569 | ///////////////// civicrm_participant_update methods | |
570 | ||
571 | /** | |
572 | * Test civicrm_participant_update with wrong params type | |
573 | */ | |
00be9182 | 574 | public function testUpdateWrongParamsType() { |
6a488035 | 575 | $params = 'a string'; |
d0e1eff2 | 576 | $result = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
577 | $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); |
578 | } | |
579 | ||
580 | /** | |
100fef9d | 581 | * Check with empty array |
6a488035 | 582 | */ |
00be9182 | 583 | public function testUpdateEmptyParams() { |
afd404ea | 584 | $params = array(); |
d0e1eff2 | 585 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
586 | $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id'); |
587 | } | |
588 | ||
589 | /** | |
100fef9d | 590 | * Check without event_id |
6a488035 | 591 | */ |
00be9182 | 592 | public function testUpdateWithoutEventId() { |
afd404ea | 593 | $participantId = $this->participantCreate(array('contactID' => $this->_individualId, 'eventID' => $this->_eventID)); |
6a488035 TO |
594 | $params = array( |
595 | 'contact_id' => $this->_individualId, | |
596 | 'status_id' => 3, | |
597 | 'role_id' => 3, | |
598 | 'register_date' => '2006-01-21', | |
599 | 'source' => 'US Open', | |
92915c55 TO |
600 | 'event_level' => 'Donation', |
601 | ); | |
d0e1eff2 | 602 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
603 | $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id'); |
604 | // Cleanup created participant records. | |
605 | $result = $this->participantDelete($participantId); | |
606 | } | |
607 | ||
608 | /** | |
100fef9d | 609 | * Check with Invalid participantId |
6a488035 | 610 | */ |
00be9182 | 611 | public function testUpdateWithWrongParticipantId() { |
6a488035 TO |
612 | $params = array( |
613 | 'id' => 1234, | |
614 | 'status_id' => 3, | |
615 | 'role_id' => 3, | |
616 | 'register_date' => '2006-01-21', | |
617 | 'source' => 'US Open', | |
92915c55 TO |
618 | 'event_level' => 'Donation', |
619 | ); | |
d0e1eff2 | 620 | $participant = $this->callAPIFailure('Participant', 'update', $params); |
6a488035 TO |
621 | } |
622 | ||
623 | /** | |
100fef9d | 624 | * Check with Invalid ContactId |
6a488035 | 625 | */ |
00be9182 | 626 | public function testUpdateWithWrongContactId() { |
6a488035 TO |
627 | $participantId = $this->participantCreate(array( |
628 | 'contactID' => $this->_individualId, | |
92915c55 TO |
629 | 'eventID' => $this->_eventID, |
630 | ), $this->_apiversion); | |
6a488035 TO |
631 | $params = array( |
632 | 'id' => $participantId, | |
633 | 'contact_id' => 12345, | |
634 | 'status_id' => 3, | |
635 | 'role_id' => 3, | |
636 | 'register_date' => '2006-01-21', | |
637 | 'source' => 'US Open', | |
92915c55 TO |
638 | 'event_level' => 'Donation', |
639 | ); | |
d0e1eff2 | 640 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
641 | $result = $this->participantDelete($participantId); |
642 | } | |
643 | ||
6a488035 TO |
644 | ///////////////// civicrm_participant_delete methods |
645 | ||
646 | /** | |
647 | * Test civicrm_participant_delete with wrong params type | |
648 | */ | |
00be9182 | 649 | public function testDeleteWrongParamsType() { |
6a488035 | 650 | $params = 'a string'; |
d0e1eff2 | 651 | $result = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
652 | } |
653 | ||
654 | /** | |
655 | * Test civicrm_participant_delete with empty params | |
656 | */ | |
00be9182 | 657 | public function testDeleteEmptyParams() { |
6a488035 | 658 | $params = array(); |
d0e1eff2 | 659 | $result = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
660 | } |
661 | ||
662 | /** | |
100fef9d | 663 | * Check with participant_id |
6a488035 | 664 | */ |
00be9182 | 665 | public function testParticipantDelete() { |
6a488035 | 666 | $params = array( |
92915c55 TO |
667 | 'id' => $this->_participantID, |
668 | ); | |
afd404ea | 669 | $participant = $this->callAPISuccess('participant', 'delete', $params); |
6a488035 TO |
670 | $this->assertAPISuccess($participant); |
671 | $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID, NULL, TRUE); | |
672 | } | |
673 | ||
674 | /** | |
100fef9d | 675 | * Check without participant_id |
6a488035 TO |
676 | * and with event_id |
677 | * This should return an error because required param is missing.. | |
678 | */ | |
00be9182 | 679 | public function testParticipantDeleteMissingID() { |
6a488035 | 680 | $params = array( |
92915c55 TO |
681 | 'event_id' => $this->_eventID, |
682 | ); | |
d0e1eff2 | 683 | $participant = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
684 | $this->assertNotNull($participant['error_message']); |
685 | } | |
c490a46a CW |
686 | |
687 | /** | |
100fef9d | 688 | * Delete with a get - a 'criteria delete' |
c490a46a | 689 | */ |
00be9182 | 690 | public function testNestedDelete() { |
92915c55 TO |
691 | $description = "Criteria delete by nesting a GET & a DELETE"; |
692 | $subfile = "NestedDelete"; | |
afd404ea | 693 | $participants = $this->callAPISuccess('Participant', 'Get', array()); |
6a488035 | 694 | $this->assertEquals($participants['count'], 3); |
afd404ea | 695 | $params = array('contact_id' => $this->_contactID2, 'api.participant.delete' => 1); |
696 | $participants = $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile, 'Get'); | |
81e1a644 | 697 | $check = $this->callAPISuccess('participant', 'getcount', array()); |
6c6e6187 | 698 | $this->assertEquals(1, $check, "only one participant should be left. line " . __LINE__); |
6a488035 | 699 | } |
c490a46a CW |
700 | |
701 | /** | |
702 | * Test creation of a participant with an associated contribution | |
703 | */ | |
00be9182 | 704 | public function testCreateParticipantWithPayment() { |
6a488035 TO |
705 | $description = "single function to create contact w partipation & contribution. Note that in the |
706 | case of 'contribution' the 'create' is implied (api.contribution.create)"; | |
707 | $subfile = "CreateParticipantPayment"; | |
708 | $params = array( | |
709 | 'contact_type' => 'Individual', | |
81e1a644 | 710 | 'display_name' => 'dlobo', |
711 | 'api.participant' => array( | |
6a488035 TO |
712 | 'event_id' => $this->_eventID, |
713 | 'status_id' => 1, | |
714 | 'role_id' => 1, | |
715 | 'format.only_id' => 1, | |
716 | ), | |
717 | 'api.contribution.create' => array( | |
718 | 'financial_type_id' => 1, | |
719 | 'total_amount' => 100, | |
720 | 'format.only_id' => 1, | |
721 | ), | |
722 | 'api.participant_payment.create' => array( | |
723 | 'contribution_id' => '$value.api.contribution.create', | |
724 | 'participant_id' => '$value.api.participant', | |
725 | ), | |
726 | ); | |
727 | ||
afd404ea | 728 | $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 | 729 | $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']); |
afd404ea | 730 | $this->callAPISuccess('contact', 'delete', array('id' => $result['id'])); |
6a488035 | 731 | } |
6a488035 | 732 | } |