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