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