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